How to split a dataframe into 2 to 3 subsets?

Want to split a data frame based on row number, in SAS, it can be achived like this:
data d1 d2 d3;
set mydata;
if N le 200 then output d1,
if N between 201 and 500 then output d2;
else output d3;
run;

how to do the same procedure by R-Studio? Thank you!

Is this what you are looking for?

d1 <- mydata[1:200,]
d2 <- mydata[201:500,]
d3 <- mydata[501:(nrow(mydata)),]
1 Like

Thank you so much!
appreciate your help!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.