extract column in multiple files in R

Hello everyone.

I want to extract a specific column from some .csv files that have same rows and columns.

I wrote the code below and it works but without the column names. (see the screen shot)

The question is how I can save the selected each column with files names.

mylist <- list.files(path = "Y:/project2020/Data/texture/Extracting_data", pattern = "*.csv", full.names = T)
mass<- lapply(mylist, function(i){
x= read.csv(i)
x= x[c(42:140), c(2)]
print (mass)
write.csv(mass, file = "Y:/project2020/Data/texture/output.csv", row.names = F)

If we assume the data in MASS is numeric, it looks I think you have column names. The top row of that screenshot looks like character data. How you gt those names I don't know.

What happens if you issue the command


We need some sample data to work with.