I am trying to sample a subset from a matrix using sample. The size of the matrix is 20X 1532. It works fine with this, but when I transpose the matrix and try to sample it, it returns null. pick.set<-sample(tissue.exp.t,5,replace=FALSE,prob=NULL) Is there something that I am missing here ? Thanks ../Murli
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
T. Murlidharan Nair wrote:> I am trying to sample a subset from a matrix using sample. > The size of the matrix is 20X 1532. It works fine with this, > but when I transpose the matrix and try to sample it, it returns > null. pick.set<-sample(tissue.exp.t,5,replace=FALSE,prob=NULL)>> Is there something that I am missing here ? Thanks ../MurliYes: tissue.exp.t is not a matrix. Check it with, e.g., str(). Uwe Ligges> ______________________________________________ > 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
See below. On Thu, 2005-02-10 at 14:53 -0800, T. Murlidharan Nair wrote:> Just to explain my previous mail, here is the output I get. > > > > dim(tissue.exp) > [1] 1532 20What is this object ? Try class(tissue.exp)> > pick<-sample(tissue.exp,5,replace=TRUE) > > dim(pick) > [1] 1532 5>From help(sample) :sample(x, size, replace = FALSE, prob = NULL) x: Either a (numeric, complex, character or logical) vector of more than one element from which to choose, or a positive integer. x has to be a vector or positive integer integer. I am not sure how you got "sample" to work on tissue.exp in the first place. Maybe you got your own version of "sample".> > 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 >
It seems that sample picks columns when the object is turned into a data.frame. I do not knoe why it is doing that.... Is this something that was meant and not documented or something? Jean On Fri, 11 Feb 2005, Adaikalavan Ramasamy wrote:> See below. > > On Thu, 2005-02-10 at 14:53 -0800, T. Murlidharan Nair wrote: > > Just to explain my previous mail, here is the output I get. > > > > > > > dim(tissue.exp) > > [1] 1532 20 > > What is this object ? Try class(tissue.exp) > > > > pick<-sample(tissue.exp,5,replace=TRUE) > > > dim(pick) > > [1] 1532 5 > > >From help(sample) : > > sample(x, size, replace = FALSE, prob = NULL) > > x: Either a (numeric, complex, character or logical) vector of > more than one element from which to choose, or a positive > integer. > > x has to be a vector or positive integer integer. I am not sure how you > got "sample" to work on tissue.exp in the first place. Maybe you got > your own version of "sample". > > > > > 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 > > > > ______________________________________________ > 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 >
?sample says: x Either a (numeric, complex, character or logical) vector of more than one element from which to choose, or a positive integer so I guess it wasn't meant to be used on a data frame. However, a data frame is a list (where the variables are the components), and a list is a vector, so the behavior is consistent:> x <- list("a", 2, "c", 4, "e", "f") > sample(x)[[1]] [1] "c" [[2]] [1] "a" [[3]] [1] 4 [[4]] [1] 2 [[5]] [1] "f" [[6]] [1] "e" Andy> From: Jean Eid > > It seems that sample picks columns when the object is turned into a > data.frame. I do not knoe why it is doing that.... > > Is this something that was meant and not documented or something? > > > Jean > > > On Fri, 11 Feb 2005, Adaikalavan Ramasamy wrote: > > > See below. > > > > On Thu, 2005-02-10 at 14:53 -0800, T. Murlidharan Nair wrote: > > > Just to explain my previous mail, here is the output I get. > > > > > > > > > > dim(tissue.exp) > > > [1] 1532 20 > > > > What is this object ? Try class(tissue.exp) > > > > > > pick<-sample(tissue.exp,5,replace=TRUE) > > > > dim(pick) > > > [1] 1532 5 > > > > >From help(sample) : > > > > sample(x, size, replace = FALSE, prob = NULL) > > > > x: Either a (numeric, complex, character or logical) vector of > > more than one element from which to choose, or a positive > > integer. > > > > x has to be a vector or positive integer integer. I am not > sure how you > > got "sample" to work on tissue.exp in the first place. Maybe you got > > your own version of "sample". > > > > > > > > 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 > > > > > > > > ______________________________________________ > > 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 > >