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

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to