[R] matrix manipulation problem

Charles C. Berry cberry at tajo.ucsd.edu
Wed Sep 2 01:37:48 CEST 2009


On Tue, 1 Sep 2009, Gregory Gentlemen wrote:

> Dear fellow R-users,
>
> Say we have a matrix x, defined as follows
>
> set.seed(50)
> x <- matrix(rbinom(100*5,1, p=0.75),nrow=100, ncol=5)
>
> Now the interpretation of x is that each for of x is actually a sequence 
> of length 5, and i would like to transform x in such a way that I can 
> describe the frequencies of sequences observed among the 100. How can I 
> do this efficiently?

If I understood the previous para:

 	as.data.frame( xtabs( ~. , as.data.frame( x ) ) )

HTH,

Chuck

>
> Thanks for any assistance!
> Greg
>
>
>
>      __________________________________________________________________
> [[elided Yahoo spam]]
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>

Charles C. Berry                            (858) 534-2098
                                             Dept of Family/Preventive Medicine
E mailto:cberry at tajo.ucsd.edu	            UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901




More information about the R-help mailing list