If the result is limited to just the counts of 1,2 and 3, you can do
the following:
> habs <- matrix(sample(1:3, 50, TRUE, prob=c(.6,.2,.2)),5,10)
> habs
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,]132113111 2
[2,]12313
Hi,
Try apply function:
apply(matrix,1,table)
Regards
M
Le 08/06/11 08:23, the_big_kowalski a écrit :
> Hi,
>
> I have a matrix
> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
> [1,]131131123 2
> [2,]131211
here's the code to generate the matrix
set.seed(1)
types = c(1,2,3)
n=5
p=1
pop.props = c(0.6,0.2,0.2)
x=matrix(pop.props,nrow=n,ncol=length(pop.props), byrow=T)
b=10
habs = rMultinom((x),b)
print(habs)
--
View this message in context:
http://r.789695.n4.nabbl
Hi,
I have a matrix
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,]131131123 2
[2,]131211122 1
[3,]122321112 1
[4,]321113121
4 matches
Mail list logo