
i
i
“K23166” — 2015/1/28 — 9:35 — page 31 — #57
i
i
i
i
i
i
2.6. EXAMPLES 31
> tally(~ female + gender, margin=FALSE, data=newds)
gender
female Male Female
0 346 0
1 0 107
2.6.4 Sorting and subsetting datasets
It is often useful to sort datasets (2.3.10) by the order of a particular variable (or variables).
Here we sort by CESD and drinking.
> library(dplyr)
> newds = arrange(ds, cesd, i1)
> newds[1:5, c("cesd", "i1", "id")]
cesd i1 id
1 1 3 233
2 3 1 139
3 3 13 418
4 4 4 251
5 4 9 95
It is sometimes necessary to create data that is a subset (2.3.1) of other data. Here we make
a dataset that only includes female subjects. First, we create the subset and calculate a
summary ...