Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ddply for entire data with no groups?

Tags:

r

plyr

Is it possible to use ddply to summarize the data without stratifying by a group? I've tried something like

ddply(df, summarize, a = sum(a, na.rm=T), b = sum(b, na.rm=T))
like image 983
user2340706 Avatar asked Nov 23 '25 05:11

user2340706


1 Answers

The function ddply will accept an "empty" grouping variable and perform the analysis on the entire table.

With subgroups:

ddply(baseball, .(lg), c("nrow", "ncol"))
  lg  nrow ncol
1       65   22
2 AA   171   22
3 AL 10007   22
4 FL    37   22
5 NL 11378   22
6 PL    32   22
7 UA     9   22

Without subgroups:

ddply(baseball, .(), c("nrow", "ncol"))
   .id  nrow ncol
1 <NA> 21699   22
like image 159
Andrie Avatar answered Nov 25 '25 19:11

Andrie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!