[R] finding the most frequent row

Liaw, Andy andy_liaw at merck.com
Sat Dec 11 16:22:03 CET 2004


> From: Kjetil Brinchmann Halvorsen
> 
> bogdan romocea wrote:
> 
> >Here's something that works. I'm sure there are better solutions (in
> >particular the paste part - I couldn't figure out how to avoid typing
> >a[i,1], ..., a[i,10]).
> >
> >a <- matrix(nrow=1000,ncol=10)
> >for (i in 1:1000)
> >	for (j in 1:10)
> >		a[i,j] <- sample(1:0,1)
> >
> >b <- vector(mode="character")
> >for (i in 1:1000)
> >	b[i] <- paste(a[i,1],a[i,2],a[i,3],a[i,4],a[i,5],
> >		a[i,6],a[i,7],a[i,8],a[i,9],a[i,10],sep="")
> >  
> >
> Or
> 
> b <- apply(a, 1, function(x) paste(x, sep="", collapse=""))

Or, as Peter pointed out recently:

  b <- apply(a, 1, paste, sep="", collapse="")

Andy
 
> Kjetil
> 
> >#the most frequent row
> >table(b)[table(b) == max(table(b))]
> >
> >HTH,
> >b.
> >
> >
> >-----Original Message-----
> >From: Lisa Pappas [mailto:lisa.pappas at hci.utah.edu]
> >Sent: Thursday, December 09, 2004 5:15 PM
> >To: r-help at stat.math.ethz.ch
> >Subject: [R] finding the most frequent row
> >
> >
> >I am bootstrapping using a function that I have defined.  The
> >"Statistic" of the function is an array of 10 numbers.  Therefore if
> >I use 1000 replications,  the "t" matrix will have 1000 rows each of
> >which is a bootstrap replicate of this 10 number array (10 columns). 
> >Is there any easy way in R to determine which row appears the most
> >frequently? 
> >
> >Thanks,
> >Lisa Pappas
> >
> >Huntsman Cancer Institute wishes to promote open communication while
> >protecting confidential and/or privileged information.  If you have
> >received this message in error, please inform the sender and delete
> >all copies.
> >
> >______________________________________________
> >R-help at stat.math.ethz.ch mailing list
> >https://stat.ethz.ch/mailman/listinfo/r-help
> >PLEASE do read the posting guide!
> >http://www.R-project.org/posting-guide.html
> >
> >______________________________________________
> >R-help at stat.math.ethz.ch mailing list
> >https://stat.ethz.ch/mailman/listinfo/r-help
> >PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html
> >
> >
> >  
> >
> 
> 
> -- 
> 
> 
> Kjetil Halvorsen.
> 
> Peace is the most effective weapon of mass construction.
>                --  Mahdi Elmandjra
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html
> 
>




More information about the R-help mailing list