[R] sequential row selection in dataframe

From: Pedro Mardones <mardones.p_at_gmail.com>
Date: Tue 26 Dec 2006 - 05:07:57 GMT

Dear all;

I'm wondering if there is any 'efficient' approach for selecting a sample of 'every nth rows' from a dataframe. For example, let's use the dataframe GAGurine in MASS library:

> length(GAGurine[,1])

[1] 314

# select an 75% of the dataset, i.e. = 236 rows, every 2 rows starting from row 1
> test<-GAGurine[seq(1,314,2),]
> length(test[,1])
[1] 157

# so, I still need another 79 rows, one way could be: test2<-GAGurine[-seq(1,314,2),]
> length(test2[,1])

[1] 157
> test3<-test2[seq(1,157,2),]

# and then
> length(final[,1])

[1] 236

Does anyone have a better idea to get the same results but without creating different datasets like test2 and test3?


R-help@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 and provide commented, minimal, self-contained, reproducible code. Received on Tue Dec 26 16:17:15 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 29 Dec 2006 - 04:30:26 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.