I have the following code which goes through a list of files in folder and reads each into a data frame which is named based on the original file name:
myfiles = list.files(pattern="*.avg")
for (file in myfiles){
dataname = paste("S",gsub("_","",gsub("\\.avg", "", file)), sep = "")
assign(dataname, read.table(file, header = FALSE, col.names = c("wl","ref","sd")))
}
My problem is that once I have the 100 dataframes read into R, I cannot then access them directly using the variable dataname as this is a character string e.g "dataframe1".... I wish to have a further few statements within the loop to process each dataframe and hence need to access the dataframe. Any ideas on how I can do this?
?getgetbut even better would be to store all the data.frames in a list, and then access via normal list indexing (name or number)mget. You can passmgeta vector of data frame names and it will return the list.