[R] sample

Jean Eid jeaneid at chass.utoronto.ca
Fri Feb 11 14:13:04 CET 2005


that is because your first object is a data.frame but when you transposed
it you turned it into a matrix. so doing

> mat1 <- data.frame(matrix(rnorm(20*1532), ncol=20))
> mat2 <- t(mat1)
> dim(sample(mat1, 5, replace=T))
[1] 1532    5
> dim(sample(mat2, 5, replace=T))
NULL
> length(sample(mat2, 5, replace=T))
[1] 5
> dim(sample(as.data.frame(mat2), 5, replace=T))
[1] 20  5


It seems that all you want is to pick columns at random so why don't you
just pick columns

> mat1 <- matrix(rnorm(20*1532), ncol=20)
> dim(mat1[, sample(1:20, 5, replace=T)])
[1] 1532    5
> dim(t(mat1)[, sample(1:1532, 5, replace=T)])
[1] 20  5



Jean





On Thu, 10 Feb 2005, T. Murlidharan Nair wrote:

> Just to explain my previous mail, here is the output I get.
>
>
>  > dim(tissue.exp)
> [1] 1532   20
>  > pick<-sample(tissue.exp,5,replace=TRUE)
>  > dim(pick)
> [1] 1532    5
>  > tissue.exp.t<-t(tissue.exp)
>  > dim(tissue.exp.t)
> [1]   20 1532
>  > pick<-sample(tissue.exp.t,5,replace=TRUE)
>  > dim(pick)
> NULL
>
> --------
> Thanks ../Murli
>
> ______________________________________________
> 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