Following up from this previous question; consolidating data frames in R using lapply works perfectly to read and combine multiple csv files.
My question is, say you also want to create and append an identifier to this merged dataset based on the filename you are reading in.
For example if you have 2 datasets and they are;
file 2014_1.csv;
Var1 Var2
21 140
2 134
3 135
file 2014_2.csv;
Var1 Var2
21 131
2 134
I want my final table to look like this;
Var1 Var2 Period
21 140 2014_1
2 134 2014_1
3 135 2014_1
21 131 2014_2
2 134 2014_2
Is there a way to do this?