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?
dat[1:150,]
dat[150:200,]
help('[')
1 to 150
151 to 200
split
list
split(dat, as.numeric(gl(nrow(dat), 150, nrow(dat)))
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,]
dat[1:150,]
anddat[150:200,]
? Readhelp('[')
- etienne1 to 150
and151 to 200
? - user3710546split
the dataset in to two in alist
bysplit(dat, as.numeric(gl(nrow(dat), 150, nrow(dat)))
- akrun