Skip to content

Subsetting data systematically

3 messages · Peter Alspach, gibberish

#
I would like to subset data from a larger dataset and generate a smaller
dataset.  However, I don't want to use sample() because it does it randomly. 
I would like to take non-random subsamples, for example, every 2nd number,
or every 3rd number.  Is there a procedure that does this? 

Thanks, Nate

--
View this message in context: http://r.789695.n4.nabble.com/Subsetting-data-systematically-tp3618516p3618516.html
Sent from the R help mailing list archive at Nabble.com.
#
Tena koe Nate

You can use the fact that R recycles.  If yourData is a dataframe, then (as examples):

yourData[c(TRUE,FALSE),] will give you every second row, starting with the first.  Similarly,
yourData[c(FALSE,TRUE,FALSE),] will give every third row, starting with the second; and
yourData[c(TRUE, rep(FALSE,19)),] will give every twentieth row, starting with the first.

There's also seq().

HTH ....

Peter Alspach.
The contents of this e-mail are confidential and may be subject to legal privilege.
 If you are not the intended recipient you must not use, disseminate, distribute or
 reproduce all or any part of this e-mail or attachments.  If you have received this
 e-mail in error, please notify the sender and delete all material pertaining to this
 e-mail.  Any opinion or views expressed in this e-mail are those of the individual
 sender and may not represent those of The New Zealand Institute for Plant and
 Food Research Limited.
1 day later