The question is very similar to this one . It is intended to combine a list of data frames into one longer data frame. However, I want to save the information from which the list item was obtained by adding an additional column with the index (id or source) of the list.
This is the data (borrow code from a related example):
dfList <- NULL set.seed(1) for (i in 1:3) { dfList[[i]] <- data.frame(a=sample(letters, 5, rep=T), b=rnorm(5), c=rnorm(5)) }
Using the code below provides a concatenated data frame, but does not add a column to the list index .:
df <- do.call("rbind", dfList)
How to combine data frames in a list when creating a column to capture a source in a list? Something like the following:

Thank you in advance.
source share