unexpected behavior: aaply(data,2,class) returns “data.frame” for all columns #82

Closed
jlegewie opened this Issue May 22, 2012 · 1 comment

Comments

Projects
None yet
2 participants

aaply(data,2,class) returns "data.frame" for all columns, which I think is unexpected. Instead it should return the class of the respective column in the data.frame. This also has direct practical implications. Using aaply(data,2,mean) throughs a warning 1: mean(<data.frame>) is deprecated. and will probably not work in future versions of R.
Using a*ply with data.frames is a documented feature and it is important to work with the columns and rows of a data.frame. I think it should treat the different columns as vectors of the respective class and not as nx1 data.frames.

Here is a stackoverflow discussion about this and some code to illustrate.

data=data.frame(str=rep("str",3),num=c(1:3))

class(data[,1])
# "factor"
class(data[,2])
# "integer"

aaply(data,2,class)
# "data.frame" "data.frame"

aaply(data,2,mean)
#1: mean(<data.frame>) is deprecated.
#    Use colMeans() or sapply(*, mean) instead.
Owner

hadley commented Oct 5, 2012

Per my comment, I think this is correct behaviour.

@hadley hadley closed this Oct 5, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment