I am attempting to create a simple loop in R, where I have a large dataset and I want to create multiple smaller samples from this dataset and export them to excel:
I thought it would work like this, but it doesn't:
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 would need to preserve and restore your data when doing a loop like this, but is this also necessary in R?