-2

I have a data.frame that is 75 rows by 25 columns. I need to take 10, 20, 30, etc... random samples from the data in the data.frame. How can I take random samples from this data.frame. I do not want to get random rows, but specifically random samples from the data.frame. The sample() function seems to only give me random rows, but I only need 10 random samples from the 1875 data points. How do I do this?

  • You are essentially asking to treat a dataframe as a matrix. That question has been asked and answered. You can either use the second answer (which used row and column sampling) or convert to matrix and use either answer to the duplicate question. – IRTFM Jan 27 '17 at 21:14

1 Answers1

0

You can also sample the rows and columns independently and then call the matrix created by those row/column combinations.

df[sample(nrow(df), 10, replace=T), sample(ncol(df), 10, replace=T)]
juliamm2011
  • 136
  • 3