[R] ave(x, y, FUN=length) produces character output when x is character
Mike Miller
mbmiller+l at gmail.com
Wed Dec 24 21:44:21 CET 2014
On Wed, 24 Dec 2014, Nordlund, Dan (DSHS/RDA) wrote:
> For your character vector example, this will get you the counts.
>
> table(charvec)[charvec]
>
> Hope this is helpful,
It does help, Dan! I came up with the same idea and expanded on it a bit
to work properly with other kinds of vectors:
as.vector(table( as.character(vec) )[as.character(vec)])
If there are, say, 10,000 different elements in vec, each repeated an
average of 5-10 times, will this still work correctly? In other words,
the length of the table output array is unlimited, right?
Mike
More information about the R-help
mailing list