mrquad mrquad - 1 year ago 131
R Question

Using summarise function to make sumIF with the dplyr package

I am using the

to make a sumIF function on my data frame. However, it does not give me the desired output:

> dput(sys)
structure(list(NUMERIC = c(244L, 24L, 1L, 2L, 4L, 111L, 23L,
2L, 3L, 4L, 24L), VAL = c("FALSE", "FALSE", "TES", "TEST", "TRUE",
"TRUE", "TRUE", "asdfs", "asdfs", "safd", "sd"), IDENTIFIER = c(99L,
99L, 98L, 98L, 99L, 99L, 99L, 13L, 13L, 99L, 12L)), .Names = c("NUMERIC",
"VAL", "IDENTIFIER"), row.names = c(NA, 11L), class = c("grouped_dt",
"tbl_dt", "tbl", "grouped_dt", "tbl_dt", "tbl", "data.table",
"data.frame"), .internal.selfref = <pointer: 0x0000000000100788>, sorted = c("VAL",
> sys <- group_by(sys, VAL, IDENTIFIER)
> df.summary <- summarise(sys,
+ numeric = sum(NUMERIC)
+ )
> (df.summary)
1 442

My desired result should look like that:

snapshot of data and result

Any recommendation as to what I am doing wrong?

Answer Source

This could occur when you have plyr loaded along with dplyr. You can either do this on a new R session or use

                     numeric = sum(NUMERIC)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download