[R] ddply from plyr package - any alternatives?

Paul Hiemstra paul.hiemstra at knmi.nl
Fri Aug 26 13:19:02 CEST 2011


 On 08/26/2011 09:14 AM, AdamMarczak wrote:
> Thank you all for suggestions, they were great and informative. 
> I will surely use data.tables in future when our server will be upgraded for
> now this is solution that I used. This solution performs exactly same task
> and produces exact same results at ddply.
>
>
>   s <- split(past, paste(past$"CNTRY_NAME",past$"SEG_NAME"))	
>   R2 <- lapply(s, function(x) return(list(x$"CNTRY_NAME"[1], x$"SEG_NAME[1],
> summary(lm(VAL~fy,x))$r.squared)));
>   R2 <- data.frame(do.call(rbind, R2))
>   R2[,1] <- unlist(R2[,1]); R2[,2] <- unlist(R2[,2]); R2[,3] <-
> unlist(R2[,3]);
>   colnames(R2)[1:3] <- c("CNTRY_NAME","SEG_NAME","V1")
>   R2<-R2[order(R2$CNTRY_NAME,R2$SEG_NAME),]

Is it much faster than ddply? And why not use data.table? You do not
need a new server to benefit from the speed gain.

Paul
>
> Above lines produce exactly same result as ddply in the exactly same fashion
> allow quick replacement of ddply without any further rebuild of the code
> (sorting is just precaution).
>
> Best regards,
> Adam.
>
> --
> View this message in context: http://r.789695.n4.nabble.com/ddply-from-plyr-package-any-alternatives-tp3765936p3770352.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> 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.


-- 
Paul Hiemstra, Ph.D.
Global Climate Division
Royal Netherlands Meteorological Institute (KNMI)
Wilhelminalaan 10 | 3732 GK | De Bilt | Kamer B 3.39
P.O. Box 201 | 3730 AE | De Bilt
tel: +31 30 2206 494

http://intamap.geo.uu.nl/~paul
http://nl.linkedin.com/pub/paul-hiemstra/20/30b/770



More information about the R-help mailing list