set.seed(1)
d.A.100 = data.frame(x=runif(10), y = runif(10))
d.A.200 = data.frame(x=runif(10), y = runif(10))
d.B.100 = data.frame(x=runif(10), y = runif(10))
d.B.200 = data.frame(x=runif(10), y = runif(10))
mylist = list(d.A.100, d.A.200, d.B.100, d.B.200)
unlisted = do.call(rbind, mylist)
Let's say you make a list of dataframes like above and then you unlist them. I know I can just do a basic rbind but for later reasons this is how the data go. How can I add the name of the dataframe back into the unlisted dataframe so I have a new column 'dataname' equals to the name of the dataframe where those rows came from?
In base R. Instead of using
do.callusearray2DFin R >= 4.3. Note that You will need to have the names of the lists.If you insist on using
do.callor are stuck in older R versions, use the following code: