[R] simple question
David Winsemius
dwinsemius at comcast.net
Thu Apr 22 19:56:16 CEST 2010
On Apr 22, 2010, at 1:36 PM, Zoppoli, Gabriele (NIH/NCI) [G] wrote:
> Hi
>
> how can I find, in a vector of characters, which is the most
> frequent one?
> a <- sample(letters[1:10], 100, replace=TRUE)
> table(a)
a
a b c d e f g h i j
10 7 7 13 7 12 1 14 15 14
> max(table(a))
[1] 15
> which.max(table(a))
i
9 # so the ninth element in the table is the max
> table(a)[which.max(table(a))]
i
15 # but the table entry needs to be extracted if you want the count.
>
> Thanks
>
> Gabriele Zoppoli, MD
> Ph.D. Fellow, Experimental and Clinical Oncology and Hematology,
> University of Genova, Genova, Italy
> Guest Researcher, LMP, NCI, NIH, Bethesda MD
>
> Work: 301-451-8575
> Mobile: 301-204-5642
> Email: zoppolig at mail.nih.gov
> ______________________________________________
> R-help at r-project.org mailing list
> 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.
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list