0

I am using the dplyr 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", 
"IDENTIFIER"), vars = list(VAL, IDENTIFIER))
> 
> 
> sys <- group_by(sys, VAL, IDENTIFIER)
> df.summary <- summarise(sys, 
+                         numeric = sum(NUMERIC)
+ )
> 
> (df.summary)
  numeric
1     442

My desired result should look like that:

snapshot of data and result

Any recommendation as to what I am doing wrong?

micstr
  • 5,080
  • 8
  • 48
  • 76
Carol.Kar
  • 4,581
  • 36
  • 131
  • 264
  • 1
    I get the desired result as showed above. Can you try `dplyr::summarise(sys,..` One thing I noticed is your dataset have a lot of classes. Why not just use on data.frame and try it? – akrun Jan 30 '15 at 13:09
  • @akrun Yep you are right. During development I didn`t reload the libary. Please add as an answer, so that I can accept it! – Carol.Kar Jan 30 '15 at 13:12
  • @akrun What's the real benefit of using `require("*lib*") vs library("*lib*")`? – Carol.Kar Jan 30 '15 at 13:15
  • Please check this link http://stackoverflow.com/questions/5595512/what-is-the-difference-between-require-and-library – akrun Jan 30 '15 at 13:16

1 Answers1

1

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

 dplyr::summarise(sys, 
                     numeric = sum(NUMERIC)
  )
akrun
  • 874,273
  • 37
  • 540
  • 662