Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Closed
jlegewie opened this Issue · 1 comment

2 participants

Joscha Legewie Hadley Wickham
Joscha Legewie

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.
Hadley Wickham
Owner

Per my comment, I think this is correct behaviour.

Hadley Wickham hadley closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.