I am trying to create a simple loop in R, where I have a large dataset, and I want to create several smaller samples from this dataset and export them to excel:
I thought this would work, but it is not:
idorg <- c(1,2,3,4,5) x <- c(14,20,21,16,17) y <- c(31,21,20,50,13) dataset <- cbind (idorg,x,y) for (i in 1:4) { attempt[i] <- dataset[sample(1:nrow(dataset), 3, replace=FALSE),] write.table(attempt[i], "C:/Users/me/Desktop/WWD/Excel/dataset[i].xls", sep='\t') }
In Stata, you will need to save and restore data when executing the loop this way, but is it also necessary in R?
source share