I am importing multiple excel sheets into one dataframe using the rio
package.
WIOD_EA_EmRelEnergy <- import_list("EA 2016/Emission-relevant Energy Accounts_total.xlsx",
setclass = "tbl", rbind = TRUE)
This line of code does already exactly what I want. It adds a column at the end called "file" indicating the the number of the sheet (data from the first sheet takes the value 1 and so on).
However, I am trying that column to take the name of the sheet rather than a number. The names of the sheets are country codes ("AUS", "AUT", etc.). Thus, the data of the first sheet should not take the value 1 but rather "AUS".
This should only be a small problem but i simply do not find the solution.
Simply use
bind_rows()
indplyr
and set the arg.id = "sheet"
, then data in each sheet will be row-bind together and a new column named what you set in.id
is added to record the sheet names which the data come from.Test
Write out an excel file with 2 sheets named
AUS
andAUT
:Then