I have used lapply to apply a function to a number of data frames:
data.cleaned <- lapply(data.list, shooter_cleaning)
And then labeled each of the resulting data frames in the list according to their subject number (e.g., 100):
names(data.cleaned) <- subject.names
What I want to do is to save each new data frame as an individual .csv file based on its subject number. For example, for subject 100 I'd like the .csv file to be labeled as "100.csv" Normally to do this (for a single data frame) I would just write (where x is the data frame):
write.csv(x, "100.csv", row.names = F)
But, obviously using lapply to do this for my list of data frames will just produce many copies of "100.csv" when instead I would like the files to be unique, based on their subject number. How can I (use apply to?) save each of these data frames to their own unique .csv file?
lapply(seq_along(list), function(i) { write.csv(list[[i]], sprintf("%d.csv", i), row.names = FALSE) })
And if you want the file names to all be the same uniform character length you can usesprintf("%03d.csv", i)
– Courtier