Hi Gabriele,

This is one way but I'm sure that there is an optimal way of doing so...

x <- c("A","B","C","C","C","C","C","B","B")
name <- unique(x)             # get unique characters

freq <- c()
for (a in 1:length(name)){
freq[a] <- sum(x==name[a])}    # get frequency
out <- cbind(name,freq)
Muhammad





Zoppoli, Gabriele (NIH/NCI) [G] wrote:
Hi

how can I find, in a vector of characters, which is the most frequent one?

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.


______________________________________________
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.

Reply via email to