1

I have a data in .csv with 19020 observations. I need to split the data randomly into parts of 13020, 3000 and 3000 in R. I have tried the following code but it doesn't help me after the first step.

indexes = sample(1:nrow(HW2), size=13020)
indexes1 = sample(13020:nrow(HW2), size=16020) 

Line2 is throwing me an error though.

David Arenburg
  • 91,361
  • 17
  • 137
  • 196

1 Answers1

4

Can you use something like

index <- sample(19020)
part1 <- HW2[index[1:13020],]
part2 <- HW2[index[13021:16020],]
part3 <- HW2[index[16021:19020],]

Edited first line according to Pierre's suggestion

ekstroem
  • 5,957
  • 3
  • 22
  • 48
  • Could you accept the answer then? Keeps others from spending time on it when your issue is already solved. – Heroka Sep 22 '15 at 05:47