I created a couple of subfolders
in my folder Temp
. If the working directory is Temp
. Assuming that the number of rows in each dataset is >= 100
files <- list.files(recursive=TRUE, full.names=TRUE)
files
#[1] "./Temp1/file1.csv" "./Temp2/file2_2.csv" "./Temp2/file2.csv"
lst1 <- lapply(files, function(x) read.csv(x, sep='')[1:100,])
Pref <- sub("/[^/]+$", '', files)
The subset
files are then written to the corresponding folders along with the old
file.
invisible(lapply(seq_along(lst1), function(i)
write.csv(lst1[[i]],paste(Pref[i],paste0('Subset',
basename(files[i])), sep="/"), quote=FALSE, row.names=FALSE)))
list.files(recursive=TRUE, full.names=TRUE)
#[1] "./Temp1/file1.csv" "./Temp1/Subsetfile1.csv"
#[3] "./Temp2/file2_2.csv" "./Temp2/file2.csv"
#[5] "./Temp2/Subsetfile2_2.csv" "./Temp2/Subsetfile2.csv"
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…