-
Notifications
You must be signed in to change notification settings - Fork 65
/
short-code-long-report.brew
91 lines (61 loc) · 1.37 KB
/
short-code-long-report.brew
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
% Gergely Daróczi
% Looong report
% <%=date()%>
I have written the below report in 10 mins :)
# Dataset
Here I will do a pretty fast report on `mtcars` which is:
<%=
mtcars
%>
# Descriptives
<%=
data.frame("Average" = sapply(mtcars, mean), "Median" = sapply(mtcars, median), "Standard deviation" = sapply(mtcars, sd), "Variance" = sapply(mtcars, var))
%>
## In details
<%
for (v in names(mtcars)) {
%>
### <%=v%>
We found the folloing values here:
<%=
mtcars[, v]
%>
The mean of <%=v%> is <%=mean(mtcars[, v])%> while the standard deviation is: <%=sd(mtcars[, v])%>. The most frequent value in <%=v%> is <%=names(sort(table(mtcars[, v]), decreasing =TRUE))[1]%>, but let us check out the frequency table too:
<%=
table(mtcars[, v])
%>
Tables are boring, let us show the same with a `histogram`:
<%=
require(lattice)
histogram(mtcars[, v], xlab = v, col = sample(colors(), 1))
%>
<%
}
%>
# Correlation
And here goes a correlation table:
<%=
cor(mtcars)
%>
And the same on a graph:
<%=
I.have.time <- FALSE
if (I.have.time)
pairs(mtcars)
%>
Yeah, that latter took a while to render in an image file :)
That's not a `pander` issue.
# Some models
Okay, let us find out how `weight` affects other variables:
<%
for (v in names(mtcars)[-6]) {
%>
### <%=v%>
A simple linear model: `mtcars$wt ~ mtcars$<%=v%>`
<%=
Independent <- mtcars[, v]
lm(mtcars$wt ~ Independent)
%>
<%
}
%>