Recently I have started using R again. I am having problems with the following problem:
I have created a dataframe format in which I want to merge smaller dataframes into, based on both the columns and rows. I want to keep the dimensions of the large format dataframe and insert the data of the smaller dataframes. The tables that I am working with are quite big, but I have created some example data.
The large dataframe, which is an empty format table:
formattable <- data.frame("Agriculture" = c(NA,NA,NA,NA,NA,NA,NA,NA),"Mining" = c(NA,NA,NA,NA,NA,NA,NA,NA),
"Industry" = c(NA,NA,NA,NA,NA,NA,NA,NA),"Services" = c(NA,NA,NA,NA,NA,NA,NA,NA), "Households" = c(NA,NA,NA,NA,NA,NA,NA,NA),
row.names = c("N01 water","N02 solar", "P01 coal", "P02 natural gas", "P03 diesel", "R01 waste", "R02 residuals","R03 losses" ) )
The smaller dataframes that hold data:
data1 <- data.frame("Agriculture" = c(5,7,NA),"Mining" = c(5,6,NA),
"Services" = c(4,8,NA), "Households" = c(1,11,NA),
row.names = c("P01 coal", "P02 natural gas", "P03 diesel") )
data2 <- data.frame("Agriculture" = c(3,2),"Mining" = c(NA,5)
,"Services" = c(5,7),
row.names = c("N01 water","N02 solar") )
data3 <- data.frame("Agriculture" = c(3,6,5),"Mining" = c(NA,0,5),
"Industry" = c(5,NA,NA),"Services" = c(NA,NA,NA), "Households" = c(7,8,9),
row.names = c("R01 waste", "R02 residuals","R03 losses" ) )
As an end product, I want one large dataframe that holds all the data from the smaller dataframes. The combinations of rows and columns that are empty/zero should still be visible with the value "0". Can anyone help me with this?