[R] dplyr or plyr or both?
Jeff Newmiller
jdnewmil at dcn.davis.ca.us
Thu Sep 15 21:17:31 CEST 2016
The incorrect results are unfortunate and can trip up the inexperienced user, but this problem is straightforward to resolve if you explicitly specify which versions of the conflicting functions to use. The more interesting question I saw was whether the intent is to deprecate plyr, but so far that does not appear to be the case.
While I agree that mixing them can be trouble-prone, I think in many cases both will continue to be used.
--
Sent from my phone. Please excuse my brevity.
On September 15, 2016 10:08:05 AM PDT, Frans Marcelissen <fransiepansiekevertje at gmail.com> wrote:
>Hello Christopher and others
>:
>What cannot be stressed enough is: do not combine both packages, it
>gives
>errors and incorrect results! I will show that below
>--------------------------------------------------------
>a<-data.frame(groep=1:4,v=1:40)
>library(dplyr)
>a %>% group_by(groep) %>% summarise(m=mean(v),n=n())
># groep m n
># <int> <dbl> <int>
># 1 1 19 10
># 2 2 20 10
># 3 3 21 10
># 4 4 22 10
># correct
>
>library(plyr)
>a %>% group_by(groep) %>% summarise(m=mean(v),n=n())
>
>Error in n() : This function should not be called directly
># ???
>a %>% group_by(groep) %>% summarise(m=mean(v))
># m
># 1 20.5
>#incorrect!
>--------------------------------------------------
>
>So both n() and group_by from dplyr don't work after library(plyr)!
>
>My advice is: do not use plyr. Unfortunately plyr has some functions
>that
>are very important, and that are not in dplyr. For instance:
>rbind.fill()
>(for combining the rows of two dataframes with unequal columns). If you
>need this: do'nt library plyr, use plyr::rbind.fil
>
>Until now I have the impression that it is also possible to library
>dplyr
>after plyr, but it is better to remove plyr!
>
>This is a serious problem that has been reported before, but not solved
>(in
>dplyr 0.5.0 and plyr 1.8.4)
>
>Frams
>
>2016-09-15 16:09 GMT+02:00 Christopher W Ryan <cryan at binghamton.edu>:
>
>> I've set myself the task of learning about these packages, and about
>> tidy data concepts.
>>
>> What is the relationship between plyr and dplyr? Does the latter
>> replace the former (meaning I can concentrate on learning the
>latter)?
>> Or is there ever a need to use functions from both (meaning I should
>> learn both)?
>>
>> Thanks.
>>
>> --Chris Ryan
>>
>> ______________________________________________
>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/
>> posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> [[alternative HTML version deleted]]
>
>______________________________________________
>R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list