I have a list of dataframes. Each list element has a unique name but the column names are identical across all data frames.
I would like to paste
the name of each dataframe to the columns, so that when I cbind
them together into a single large dataframe I can distinguish between them.
Example data;
LIST <- list(df1 = data.frame("ColA" = c(1:5), "ColB" = c(10:14)),
df2 = data.frame("ColA" = c(21:25), "ColB" = c(30:34)))
str(LIST)
List of 2
$ df1:'data.frame': 5 obs. of 2 variables:
..$ ColA: int [1:5] 1 2 3 4 5
..$ ColB: int [1:5] 10 11 12 13 14
$ df2:'data.frame': 5 obs. of 2 variables:
..$ ColA: int [1:5] 21 22 23 24 25
..$ ColB: int [1:5] 30 31 32 33 34
Desired output;
List of 2
$ df1:'data.frame': 5 obs. of 2 variables:
..$ df1.ColA: int [1:5] 1 2 3 4 5
..$ df1.ColB: int [1:5] 10 11 12 13 14
$ df2:'data.frame': 5 obs. of 2 variables:
..$ df2.ColA: int [1:5] 21 22 23 24 25
..$ df2.ColB: int [1:5] 30 31 32 33 34