How do I summarise data using reshape/plyr?
Question
I have data that looks like this:
model aspect cover contour
1 flowering ~ 1 2 52 2400
2 flowering ~ 1 + temp + precip:temp 1 52 2390
3 flowering ~ 1 + temp + precip 1 52 2390
4 flowering ~ 1 + temp + precip 1 52 2390
5 flowering ~ 1 + precip + precip:temp 1 52 2400
6 flowering ~ 1 + precip + precip:temp 1 52 2400
There are 40,000 rows in this dataset with 54 unique models.
How do I get a summarized dataset showing how many times each model occurs in a aspect x contour x cover combination?
Solution
try this (assumes your data is in a data frame called myData):
comboCount <- ddply(myData, c("model","aspect","cover","contour") function(df) nrow(df))
OTHER TIPS
plyr provides an optimised function for this special case:
comboCount <- count(myData, c("model","aspect","cover","contour"))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow