0

I'm practicing R with dataframe InsectSprays (in R base), using plyr package:

ddply(InsectSprays,.(spray), summarize, sum = sum(count))

Error in .fun(piece, ...) : argument "by" is missing, with no default

I don't understand what this error mean, the tutorial did the exact the same command and has the output like this:

    spray    sum
1    A       174
2    B       184
3    C        25

and also I wanna create a new variable(still error):

spraysum <- ddply(InsectSprays,.(spray), summarize, sum = ave(count,FUN = sum)) 
Error in .fun(piece, ...) : argument "by" is missing, with no default
neilfws
  • 32,751
  • 5
  • 50
  • 63
wawawa
  • 2,835
  • 6
  • 44
  • 105
  • Perhaps you have the `dplyr` package loaded at the same time? – neilfws Nov 26 '18 at 22:10
  • umm but I didn't load dplyr – wawawa Nov 26 '18 at 22:12
  • 3
    Then try `summarise` (with s not z) instead of `summarize` as [described here](https://github.com/tidyverse/dplyr/issues/505). – neilfws Nov 26 '18 at 22:20
  • @neilfws it works for the first command, but the last one shows 'Error in summarise_impl(.data, dots) : Column sum must be length 1 (a summary value), not 12' – wawawa Nov 27 '18 at 21:16
  • Second command works fine on my machine without error. Not really related to your problem, but I'd suggest learning the `dplyr` package (and perhaps also `purrr`). They have, in a sense, superseded `plyr` and are very useful. – neilfws Nov 27 '18 at 21:30

2 Answers2

0

#cargar la librerias

library(plyr,dplyr)
ddply(InsectSprays,.(spray), summarize  ,sum=sum(count))

Result:

  spray sum
    1     A 174
    2     B 184
    3     C  25
    4     D  59
    5     E  42
    6     F 200
Steffen Moritz
  • 7,277
  • 11
  • 36
  • 55
0

Use summarise instead of summarize.

The following function just works fine.

ddply(InsectSprays,.(spray), summarise, sum = sum(count))
Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77