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: zoppo...@mail.nih.gov
______________________________________________
R-help@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
______________________________________________
R-help@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.