I need to extract column 2 from a list of multiple dataframe. I have 18 files and I was able to do it by reading each file separately.
df1 <- read.table("name.XLS", header = FALSE)
df2 <- read.table("name.XLS", header = FALSE)
df3 <- read.table("name.XLS", header = FALSE)
df4 <- read.table("name.XLS", header = FALSE)
data_list = list(df1, df2,df3,df4)
# extract column named V2
res = lapply(data_list, '[[', 2)
# convert to character
res = lapply(res, as.character)
I modified the code to read all files in the directory
folder <- "temp"
file_list <- list.files(path=folder, pattern="*.XLS")
for (i in 1:length(file_list)){
assign(file_list[i],
read.csv(paste(folder, file_list[i], sep="/"))
)}
I need to create an equivalent list to data_list that reads a list of multiple dataframe to extract column V2 from each dataframe in the list
EDIT
I tried the following code and it worked just fine
my_data <- lapply(file_list, read.table)
You can find more about lists here