I have multiple CSV files and want to read them in R. the file names are provided as an argument, so I don't know the names in advance. This is the reason, why I do it in a loop.
Next, I want each dataframe to be appended to a list. As a result, I want to have an indexed list to access access the first line of all dataframes and I think the best way to do this is to have a list of the dataframes available. If there is a more efficient way to do this, any solutions are appreciated.
But for now I will go for the having all dataframes in a list approach. For this I would like to know how I can add a dataframe to a list in a loop.
I have this code:
#splitting the args to get the filenames
splat <- strsplit(args[1], ",")[[1]]
for (fname in splat) {
#d.fname = dataframe
d.fname <- read.csv(fname, header = FALSE, sep = ",", dec = ".")
#code needed to add d.fname to a list?
}
So all in all I have two questions: 1) how can I add dataframes to a list in a loop? 2) is there a better way to do this, with the goal in mind, that later I need to have access to all dataframes like do something (e.g. create a box plot) with the first elements of the first rows of all dataframes?
I am aware of solutions like this: Importing multiple .csv files into R . However, I cannot apply this solution, since I am not able to use list.files(pattern="*.csv")
because I dont know the filenames in advance.