[R] simple question

Muhammad Rahiz muhammad.rahiz at ouce.ox.ac.uk
Thu Apr 22 19:56:13 CEST 2010


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



More information about the R-help mailing list