Last active
June 20, 2017 05:21
-
-
Save thomasfedb/f6d8d5dc9ba4558dd1eafa867715a0a5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
title: "Test" | |
output: | |
pdf_document: default | |
html_notebook: default | |
--- | |
```{r setup, include = F} | |
knitr::opts_chunk$set(echo = F, warning = F, message = F) | |
``` | |
```{r, include = F} | |
require(data.table) | |
dt <- data.table( | |
A = c(1, 4, 1, 4, 2, 4, 8), | |
B = c(2, 2, 3, 4, 3, 1, 5) | |
) | |
``` | |
# Without Loop | |
```{r, echo = F} | |
col <- "A" | |
knitr::asis_output(paste0("### Column ", col, "\n")) | |
knitr::asis_output("Counts\n") | |
dt[, .(n = .N), by = col] | |
knitr::asis_output("Statistics\n") | |
summary(dt[, get(col)]) | |
``` | |
# With Loop | |
```{r, echo = F} | |
for (col in c("A")) { | |
knitr::knit_print(paste0("### Column ", col)) | |
knitr::knit_print("Counts") | |
knitr::knit_print(dt[, .(n = .N), by = col]) | |
knitr::knit_print("Statistics") | |
knitr::knit_print(summary(dt[, get(col)])) | |
} | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment