
Dear R wizards,
 
I have a folder containing 1000 files. For each file, I need to extract the first row of each file, paste it to a new file, then write out that file. Then I need to repeat this operation for each additional row (row 2, then row 3, etc) for 23 rows in each file.
 
I can do this with a for loop (as below). 
 
Is there a way to use some of the indexing power of R to get around this nasty loop?
 
Thank you in advance for any suggestions
 
###################
newoutfile <- data.frame()
list <- list.files("c:/data")
 
file = 1
for(file in list) {
   row <- file[1, ]
   newoutfile <- rbind(row, newoutfile)
   file = file + 1
write.csv(outfile, file = "output.csv")
}
####################
 
 
	[[alternative HTML version deleted]]

