Reputation: 13
I have a data.frame with 4000 rows and 600 columns. I should divide 600 columns into 10 groups, randomly with an even group size of 60. i tried to use sample or split but answer was not right. Please guide me.
Upvotes: 0
Views: 185
Reputation: 1178
One of the way is to do this is to first rearrange the column index and then split it in the 10 equal size. Assuming df
is the data.frame following code should work
a <- sample(600)
b <- split(a, ceiling((1:600)/10))
result <- lapply(b, FUN = function(x) df[, x])
Upvotes: 1