Below is my code so far, which doesn't work. I have 7 dataframes that each contain information about one pollutant (named in pollutant_long_name). Each of these dataframes is called, for example, national_tier1_Nitrogen Oxides or national_tier1_Ammonia. I've been trying to use the paste0 function to use the values in my for loop sequence within the for loop, but it doesn't seem to be working. The first error I got is
Error: unexpected '=' in: " dplyr::group_by( inv_sector ) %>%
dplyr::summarise( paste0( "NEI_emissions_", pollutant_name, "_2011" ) ="
Basically, my end goal is the have 7 dataframes called total_2011_pollutant name that I'll then leftjoin to make a dataframe containing all 7 pollutants.
pollutant_long_name <- c( "Nitrogen Oxides", "Sulfur Dioxide", "Carbon Monoxide", "Volatile Organic Compounds",
"PM2.5 Filterable", "PM10 Filterable", "Ammonia" )
for( n in pollutant_long_name ){
pollutant_name <- paste0( n )
#===================================================================================NOX
NEI_2011 %>%
dplyr::left_join( CEDS_to_EPA_rename, by = c( "CEDS_Sector" ) ) %>%
dplyr::filter( pollutant == pollutant_name ) %>%
dplyr::group_by( inv_sector ) %>%
dplyr::summarise( paste0( "NEI_emissions_", pollutant_name, "_2011" ) = sum( emissions/1000 ) ) %>%
round_df( digits = 0 )-> NEI_2011_emissions
paste0( "national_tier1_", pollutant_name ) %>%
dplyr::select( c(Source.Category, X2011) ) %>%
dplyr::rename( inv_sector = Source.Category ) %>%
dplyr::mutate( X2011 = gsub( ",", "", X2011 ) ) %>%
dplyr::mutate( X2011 = as.numeric(as.character( X2011 ) ) ) %>%
dplyr::rename( national_2011_NOX = X2011 )-> paste0( "national_2011_", pollutant_name )
NEI_2011_emissions %>%
dplyr::left_join( paste0( "national_2011_", pollutant_name ), by = c( "inv_sector" ) ) -> paste0( "total_2011_", pollutant_name )
paste0( "total_2011_", pollutant_name )[is.na(paste0( "total_2011_", pollutant_name ))] <- 0
}