1
votes

Now I have data

dat <- data.frame(y,x1,x2) 

there are about 200 rows.

And I want to partition this data by row number

like 1 to 150 and 150 to 200

How can I do this?

1
dat[1:150,] and dat[150:200,] ? Read help('[') - etienne
Don't you mean 1 to 150 and 151 to 200? - user3710546
Yes that's right thx - Samuel Lee
You can split the dataset in to two in a list by split(dat, as.numeric(gl(nrow(dat), 150, nrow(dat))) - akrun

1 Answers

1
votes

As mentioned by @etienne use [

dat <- data.frame("y" = 1:200 , "x1" = rnorm(200), "x2" = rnorm(200)) 

dat1 <- dat[1:150,]
dat2 <- dat[151:200,]