Debian Codegraph @

inst/examples/short-code-long-report.brew

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