Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aaply on a data.frame is not consistent with apply #8

Closed
jiho opened this issue Jun 30, 2010 · 4 comments
Closed

aaply on a data.frame is not consistent with apply #8

jiho opened this issue Jun 30, 2010 · 4 comments

Comments

@jiho
Copy link
Contributor

jiho commented Jun 30, 2010

library("plyr")

d <- data.frame(x=runif(5), y=runif(5))
aaply(d, 1, mean)

I would have expected the result to be

aaply(as.matrix(d), 1, mean)

just as

apply(d, 1, mean)

i.e. simply treat the data.frame as an array since I use a*ply. Basically it seems to be doing some sort of contingency table with additional computaiton (i.e. the mean) from the data.frame, but I don't understand why it would do this from the documentation.

@hadley
Copy link
Owner

hadley commented Jun 30, 2010

I think str(alply(d, 1, mean)) should illustrate the complication - the mean of a data frame is a mean. But something is still going wrong because the output appears to have an extra dimension

@jiho
Copy link
Contributor Author

jiho commented Jun 30, 2010

I guess you mean the mean of a data.frame is a data.frame. Indeed that is another complication, but the problem is the same with sum.

@hadley
Copy link
Owner

hadley commented Jun 30, 2010

Currently, a*ply(df, 1, ...) is equivalent to d*ply(df, all vars, ...), when I think it should actually be equivalent to d*ply(df, rownames, ...).

@hadley
Copy link
Owner

hadley commented Jun 30, 2010

Fixed in 282e350

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants