Error in ddply

1,856 views
Skip to first unread message

Fritsander

unread,
Sep 20, 2010, 3:32:58 PM9/20/10
to manipulatr
Hi,

I changed Windows laptops using Tinn-R version 2.3.4.4 with R version
2.10.1 to another and freshly installed Tinn-R version 2.3.5.2 with R
2.11.1. Then using a script that works flawlessy on the former laptop
I get the following error on the latter laptop and installation:
Error: lenght(rows) ==1 is not TRUE. I tried to look up this error
message but couldn't come up with anything.

Who has an idea what has happened here?

Thanks,

Fritsander Lahr

Fritsander

unread,
Sep 20, 2010, 3:36:41 PM9/20/10
to manipulatr
Sorry,

The script executed is the following:

ddply(gwtots, .(week), summarise, wavg(PC,Original.Duration.d.)),
where .(Week) is a variable, gwtots a dataframe and wavg a function to
calculate a weighted average.

Hadley Wickham

unread,
Sep 20, 2010, 4:02:00 PM9/20/10
to Fritsander, manipulatr
Could you please provide a reproducible example? (http://gist.github.com/270442)

Hadley

> --
> You received this message because you are subscribed to the Google Groups "manipulatr" group.
> To post to this group, send email to manip...@googlegroups.com.
> To unsubscribe from this group, send email to manipulatr+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/manipulatr?hl=en.
>
>

--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

Matt Frost

unread,
Sep 20, 2010, 4:26:57 PM9/20/10
to manipulatr
I started getting the same error when I upgraded.

In my case, I appear to be causing the problem by passing something
like NewVariable='Value' among other things to a ddply function. This
sounds obscure, but here's an example.

I use ddply and cast functions to calculate the percent of total at
successive levels of aggregation and stick them together with cbind
and rbind:

bball <- subset(baseball, year > 1900 & lg %in% c('AL','NL'))
# randomly assign a fake handedness variable
bball$hand <- cut(runif(nrow(bball), min=0, max=1), c(0, .65, 0.9,
1.0), c("R","L","B"))

rbind(
cast(ddply(bball, .(lg, year), summarise, hand = hand, pct = hr /
sum(hr)), lg+year~hand, sum)
,
cast(ddply(bball, .(year), summarise, lg = 'Both Leagues', hand =
hand, pct = hr / sum(hr)), year~hand, sum)
)

In the example above, I am calculating the share of home runs by
handedness within each league, then stacking the results onto a
similar table that calculates the share for both leagues. To make the
rbind() work properly, I assigned lg = 'Both Leagues' inside the
ddply statement. That appears to break now with the error message
cited above.

I can get the results I need by running the following:

rbind(
cast(ddply(bball, .(lg, year), summarise, hand = hand, pct = hr /
sum(hr)), lg+year~hand, sum)
,
cbind(
lg='Both Leagues',
cast(ddply(bball, .(year), summarise, hand = hand, pct = hr /
sum(hr)), year~hand, sum)
)
)

With such an easy workaround, this isn't a critical issue for me, but
I thought this might help others troubleshoot.

Charlotte Wickham

unread,
Sep 20, 2010, 7:09:11 PM9/20/10
to manipulatr
I came across this error today too with something like:
ddply(data.frame(x = 1:10, y = rep(1:2, 5)), "y", summarise, quantile(x))

I just checked that this indeed worked with at least plyr_0.1.9.

Anyway a simple workaround is:
ddply(data.frame(x = 1:10, y = rep(1:2, 5)), "y", summarise, quants =
quantile(x))

Charlotte

Hadley Wickham

unread,
Sep 21, 2010, 11:23:34 PM9/21/10
to Charlotte Wickham, manipulatr
It'll be fixed in the next version.
Hadley

--

Reply all
Reply to author
Forward
0 new messages