Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error in code from split-apply-combine paper - how to resolve?

Tags:

r

plyr

To try and get to grips with data manipulations in R, I've started reading Hadley's paper on split-apply-combine.

I'm on page 3 and trying to go through the code to understand it. Unfortunately the code is erroring and my reproduction is faithful (I've done c&p and handtyped). As I'm trying to learn this stuff and I'm right at the beginning I can't actually tell what's wrong with it. I tried it on both R2.5 and R3.0

library("MASS")
library("plyr")
data(ozone)
one<-ozone[1,1,]
month<-ordered(rep(1:12,length=72))
model<-rlm(one ~ month - 1)
deseas<-resid(model)
deseasf<-function(value) {rlm(value ~ month - 1)}
models<-aaply(ozone,1:2,deseasf)
deseas<-aaply(models,1:2,resid)

Where the models line errors with Error: Results must have one or more dimensions.

Can somebody tell me whether it works for them, or what needs to be fixed/amended if it doesn't and why?





PS - Can't check on http://plyr.had.co.nz/ for errata because my work proxy currently blocks the site!

like image 820
Steph Locke Avatar asked Dec 02 '25 23:12

Steph Locke


1 Answers

It should be

models <- alply(ozone, 1:2, deseasf)
deseas <- ldply(models, resid)
like image 139
user2546224 Avatar answered Dec 05 '25 13:12

user2546224



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!