Dear all, I got one problem here and hoping someone can help me on this. Say I have a 50 by 2 matrix and I don't know how to randomly select: 1. a pair of observations from the last 10th of the 50 observation from the matrix. 2. how to select randomly an observation from the first 5 observations of the second column in the matrix? Thanks....hope to hear from someone soon -- View this message in context: http://www.nabble.com/How-to-select-randomly-from-a-matrix--tp22410551p22410551.html Sent from the R help mailing list archive at Nabble.com.
Hi r-help-bounces at r-project.org napsal dne 09.03.2009 11:29:41:> > Dear all, > > I got one problem here and hoping someone can help me on this. Say Ihave a> 50 by 2 matrix and I don't know how to randomly select: > > 1. a pair of observations from the last 10th of the 50 observation fromthe> matrix.Use ?tail for ?nrow of matrix and ?sample this and select appropriate row from matrix> 2. how to select randomly an observation from the first 5 observationsof> the second column in the matrix?the same principle applies here but use head instead. Regards Petr> > Thanks....hope to hear from someone soon > -- > View this message in context:http://www.nabble.com/How-to-select-randomly-> from-a-matrix--tp22410551p22410551.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
WXE83 wrote:> Dear all, > > I got one problem here and hoping someone can help me on this. Say I have a > 50 by 2 matrix and I don't know how to randomly select: >data <- matrix(1:25, 50, 2)> 1. a pair of observations from the last 10th of the 50 observation from the > matrix. >data[sample(41:50, 1, replace=FALSE),]> 2. how to select randomly an observation from the first 5 observations of > the second column in the matrix? >data[sample(1:5, 1, replace=FALSE),2] Ciao, domenico> Thanks....hope to hear from someone soon >
Reasonably Related Threads
- randomly select another observation with same grouping factor and year value, do for every record in dataframe
- FW: Select a random subset of rows out of matrix
- Select Random Rows from a dataframe
- Randomly remove condition-selected rows from a matrix
- randomly select duplicated entries