I have some survey data that I want to describe by political party and state.
I'm having some trouble with the by() aggregation command. It works with lots of functions, but just not length(). Eg:
by(x, list(party=nn$info$party,state=nn$info$st),mean)
works fine but not
by(x, list(party=nn$info$party,state=nn$info$st),length)
Which returns an array filled not with the count of the data I'm looking for, but just a series of 1's. This is what it looks like for Alabama:
party: D
state: AL
[1] 1
---------------------------------------------------------------------------
party: I
state: AL
[1] 1
---------------------------------------------------------------------------
party: R
state: AL
[1] 1
---------------------------------------------------------------------------
Very mystifying. Any ideas?