[R] Count occurances in integers (or strings)
Jay
josip.2000 at gmail.com
Wed Jun 15 11:09:25 CEST 2011
Hi,
I have a dataframe column from which I want to calculate the number of
1's in each entry. Some column values could, for example, be
"0001001000" and "11110000111".
To get the number of occurrences from a string I use this:
sum(unlist(strsplit(mydata[,"my_column"], "")) == "1")
However, as my data is not in string form.. How do I convert it? l
tried:
lapply(mydata[,"my_column"],toString)
but I do not seem to get it right (or at least I do not understand the
output format).
Also, are there other options? Can I easily calculate the occurrences
directly from the integers?
More information about the R-help
mailing list