I'm currently using R studio Version 1.0.143 with R version 3.4.4.
I'm trying to make a apply() function that does the following but to many files:
df1 <- read_excel("Sample 1.xlsx")
df1["Sample"] <- "Sample 1"
df2 <- read_excel("Sample 2.xlsx")
df2["Sample"] <- "Sample 2"
rbind(df1, df2) -> final
A function that adds a column to the dataframe informing to which sample the variables belong, because after I will bind all samples. Not only this function has to read many excel files, but to add a column in each file with the name of the file (as the example). I couldn't find anything similar in other questions
I tried to use lapply, but without success. I need this because I want to merge more than 100 dataframes (I could do by hand but it seems dumb to not use apply). All the files have the same columns, so there is no need for a function that puts NAs when a column is not present in one file.