I have four tables that are very much similar. I would like to combine the tables according to a filter that is set for each table according to declaration periods (DECL_PERIO)
I made sure that each of the tables have the same column names as follows:
colnames(Terr_data_HM90) <- c("OID", "ObjectID", "Value", "Count", "PA2021Q4_2",
"NVM2018_v2", "HM70LC90_20L1", "Cur_Name_1",
"DECL_PERIO", "DECL_YEAR", "LC90_20L1", "Count_NVM",
"Name_18", "CNSRV_TRGT", "ConTM")
colnames(Terr_data_HM14) <- c("OID", "ObjectID", "Value", "Count", "PA2021Q4_2",
"NVM2018_v2", "HM70LC90_20L1", "Cur_Name_1",
"DECL_PERIO", "DECL_YEAR", "LC90_20L1", "Count_NVM",
"Name_18", "CNSRV_TRGT", "ConTM")
colnames(Terr_data_HM18) <- c("OID", "ObjectID", "Value", "Count", "PA2021Q4_2",
"NVM2018_v2", "HM70LC90_20L1", "Cur_Name_1",
"DECL_PERIO", "DECL_YEAR", "LC90_20L1", "Count_NVM",
"Name_18", "CNSRV_TRGT", "ConTM")
colnames(Terr_data_HM20) <- c("OID", "ObjectID", "Value", "Count", "PA2021Q4_2",
"NVM2018_v2", "HM70LC90_20L1", "Cur_Name_1",
"DECL_PERIO", "DECL_YEAR", "LC90_20L1", "Count_NVM",
"Name_18", "CNSRV_TRGT", "ConTM")
My code to create the combined table according to the filters as follows:
Terra_data <- as.data.frame((Terr_data_HM90 %>% filter(DECL_PERIO == "1901-1950"| DECL_PERIO =="1951-2000"| DECL_PERIO =="2001-2010"|DECL_PERIO =="2011-2015" )),
(Terr_data_HM14 %>% filter(DECL_PERIO == "2016"| DECL_PERIO =="2017")),
(Terr_data_HM18 %>% filter(DECL_PERIO == "2018"| DECL_PERIO =="2019")),
(Terr_data_HM20 %>% filter(DECL_PERIO == "2020"| DECL_PERIO =="2021")))
The code worked but only for the first filter and does not include the filters for Terr_data_HM14 to HM20. I am not sure what I am doing incorrectly.
I can use the tables separately in a calculation and at the end join my final results according to the specified filters in the code above. But I thought it would be better to create one table so that I can run the calculation code once and not four times.