On Feb 14, 2012, at 8:02 PM, lawonga wrote:

Hi, I am new at R and have been looking for a guide on how to do this with no
avail. I have a data set similar to this:

X   Y
1   2
3   3
4   9
2   4
6   3
9   1
1   7
0   2
5   6
3   8

If by dataset you mean a daaframe named (for discussion purposes) "dfrm", then this will give you the first five row

dfrm[1;5, ]

And this will give you the rest:

dfrm[ -(1:5), ]



and I need it to be split into something like this:

X   Y
1   2
3   3
4   9
2   4
6   3

X  Y
9   1
1   7
0   2
5   6
3   8

I am thinking I need to write a loop because my data set is much larger than this (1000) and I need it all organized into smaller data sets of 5's. Can
someone point me in the write direction?

Oh .... So you want to split into packets of 5 rows each?

try:

split( dfrm, 1:NROW(dfrm) %/% 5 )

--

David Winsemius, MD
West Hartford, CT

______________________________________________
R-help@r-project.org 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.

Reply via email to