Dear mr/madam I have 3 matrix with 20 rows and 3 columns like this: I want to sample randomly from three matrix and put it in a vector.How can i do that? Young.list1<- matrix(NA,nrow= 20,ncol=3) Young.list1[,1]<- 1:20 Young.list1[,2]<- 0.6 Young.list1[,3]<- 500 colnames(Young.list1)<- c("ID","r","EBV") ########################################### Young.list2<- matrix(NA,nrow= 20,ncol=3) Young.list2[,1]<- 21:40 Young.list2[,2]<- 0.7 Young.list2[,3]<- 600 colnames(Young.list2)<- c("ID","r","EBV") ########################################### Young.list3<- matrix(NA,nrow= 20,ncol=3) Young.list3[,1]<- 41:60 Young.list3[,2]<- 0.8 Young.list3[,3]<- 700 colnames(Young.list3)<- c("ID","r","EBV") [[alternative HTML version deleted]]
Hello, What do you want to sample? Rows? With or without replacement? You need to give us more information on what you want. Start by seeing the help page for ?sample Hope this helps, Rui Barradas ? Citando MARYAM <firoozi_maryam6858 at yahoo.com>:> Dear mr/madam > I have 3 matrix with 20 rows and 3 columns like this: I want to > sample randomly from three matrix and put it in a vector.How can i > do that? > > Young.list1<- matrix(NA,nrow= 20,ncol=3) > Young.list1[,1]<- 1:20 > Young.list1[,2]<- 0.6 > Young.list1[,3]<- 500 > colnames(Young.list1)<- c("ID","r","EBV") > ########################################### > Young.list2<- matrix(NA,nrow= 20,ncol=3) > Young.list2[,1]<- 21:40 > Young.list2[,2]<- 0.7 > Young.list2[,3]<- 600 > colnames(Young.list2)<- c("ID","r","EBV") > ########################################### > Young.list3<- matrix(NA,nrow= 20,ncol=3) > Young.list3[,1]<- 41:60 > Young.list3[,2]<- 0.8 > Young.list3[,3]<- 700 > colnames(Young.list3)<- c("ID","r","EBV") > ? ? ? ? [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.htmland provide commented, > minimal, self-contained, reproducible code.? [[alternative HTML version deleted]]
Hi Maryam, Sounds like: c(Young.list1[sample(1:20,1),],Young.list2[sample(1:20,1),],Young.list3[sample(1:20,1),]) to me. Jim On Wed, Jan 20, 2016 at 7:35 AM, <ruipbarradas at sapo.pt> wrote:> Hello, > > What do you want to sample? Rows? With or without replacement? You > need to give us more information on what you want. > > Start by seeing the help page for ?sample > > Hope this helps, > > Rui Barradas > > > Citando MARYAM <firoozi_maryam6858 at yahoo.com>: > > > Dear mr/madam > > I have 3 matrix with 20 rows and 3 columns like this: I want to > > sample randomly from three matrix and put it in a vector.How can i > > do that? > > > > Young.list1<- matrix(NA,nrow= 20,ncol=3) > > Young.list1[,1]<- 1:20 > > Young.list1[,2]<- 0.6 > > Young.list1[,3]<- 500 > > colnames(Young.list1)<- c("ID","r","EBV") > > ########################################### > > Young.list2<- matrix(NA,nrow= 20,ncol=3) > > Young.list2[,1]<- 21:40 > > Young.list2[,2]<- 0.7 > > Young.list2[,3]<- 600 > > colnames(Young.list2)<- c("ID","r","EBV") > > ########################################### > > Young.list3<- matrix(NA,nrow= 20,ncol=3) > > Young.list3[,1]<- 41:60 > > Young.list3[,2]<- 0.8 > > Young.list3[,3]<- 700 > > colnames(Young.list3)<- c("ID","r","EBV") > > [[alternative HTML version deleted]] > > > > ______________________________________________ > > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide > > http://www.R-project.org/posting-guide.htmland provide commented, > > minimal, self-contained, reproducible code. > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.[[alternative HTML version deleted]]
Hello, Please respond to the list, not just to me. If you just want the first vector ofm the matrices, try the following. fun <- function(..., n, replace = FALSE){ ?? ?m <- do.call(rbind, list(...)) ?? ?idx <- sample(nrow(m), n, replace = replace) ?? ?m[idx, 1] } n <- 3 * nrow(Young.list1) * 0.25 fun(Young.list1, Young.list2, Young.list3, n = n, replace = FALSE) Hope this helps, Rui Barradas Citando MARYAM <firoozi_maryam6858 at yahoo.com>:> Hello, I want to select randomly to three matrix with fixed > number.for example i want to select 25% from three matrix > randomly(select first column of each matrix). On Dey 30, 1394 AP, at > 0:05, ruipbarradas at sapo.pt wrote: > ? >> ?Hello, What do you want to sample? Rows? With or without replacement? You need to give us more information on what you want. Start by seeing the help page for ?sample Hope this helps, Rui Barradas ? Citando MARYAM <firoozi_maryam6858 at yahoo.com>:> Dear mr/madam > I have 3 matrix with 20 rows and 3 columns like this: I want to > sample randomly from three matrix and put it in a vector.How can i > do that? > > Young.list1<- matrix(NA,nrow= 20,ncol=3) > Young.list1[,1]<- 1:20 > Young.list1[,2]<- 0.6 > Young.list1[,3]<- 500 > colnames(Young.list1)<- c("ID","r","EBV") > ########################################### > Young.list2<- matrix(NA,nrow= 20,ncol=3) > Young.list2[,1]<- 21:40 > Young.list2[,2]<- 0.7 > Young.list2[,3]<- 600 > colnames(Young.list2)<- c("ID","r","EBV") > ########################################### > Young.list3<- matrix(NA,nrow= 20,ncol=3) > Young.list3[,1]<- 41:60 > Young.list3[,2]<- 0.8 > Young.list3[,3]<- 700 > colnames(Young.list3)<- c("ID","r","EBV") > ? ? ? ? [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.htmland[1] provide commented, > minimal, self-contained, reproducible code.? ? Liga??es: --------- [1] http://www.r-project.org/posting-guide.htmland [[alternative HTML version deleted]]
Hi Maryam, c(Young.list1[sample(1:20,5),], Young.list2[sample(1:20,5),], Young.list3[sample(1:20,5),]) # or for a more general solution nrows<-dim(Young.list1)[1] c(Young.list1[sample(1:nrows,nrows/4),], Young.list2[sample(1:nrows,nrows/4),], Young.list3[sample(1:nrows,nrows/4),]) Jim On Wed, Jan 20, 2016 at 9:03 PM, maryam firoozi < firoozi_maryam6858 at yahoo.com> wrote:> thanks for repling.can you help me how to select randomely 25% from three > mattix and put it in a vector. > >[[alternative HTML version deleted]]