The other day I was reading the following lines in R and I don't understand what the %>%
and summarise(n=n())
and summarise(total=n())
meant. I understand the group_by
and ungroup
methods though.
Can someone help out? There isn't any documentation for this either.
library(dplyr)
net.multiplicity <- group_by(net, nodeid, epoch) %>% summarise(n=n()) %>%
ungroup() %>% group_by(n) %>% summarise(total=n())
This is from the dplyr
package. n=n()
means that a variable named n
will be assigned the number of rows (think number of observations) in the summarized data.
the %>%
is read as "and then" and is way of listing your functions sequentially rather then nesting them. So that command is saying you should do the grouping and then summarize
the result of the grouping by the number of rows in each group and then ungroup
that result, and then group the un-grouped data based on n
and then summarize
that by the total number of rows in each of the new groups.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With