R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

PM2.5 data from 1999, 2002, 2005, 2008

Grading Criteria Overview

For each question

  1. Does the plot appear to address the question being asked?

  2. Is the submitted R code appropriate for construction of the submitted plot?

Data

The zip file contains two files:

PM2.5 Emissions Data (summarySCC_PM25.rds): This file contains a data frame with all of the PM2.5 emissions data for 1999, 2002, 2005, and 2008. For each year, the table contains number of tons of PM2.5 emitted from a specific type of source for the entire year. Here are the first few rows.

##     fips      SCC Pollutant Emissions  type year
## 4  09001 10100401  PM25-PRI    15.714 POINT 1999
## 8  09001 10100404  PM25-PRI   234.178 POINT 1999
## 12 09001 10100501  PM25-PRI     0.128 POINT 1999
## 16 09001 10200401  PM25-PRI     2.036 POINT 1999
## 20 09001 10200504  PM25-PRI     0.388 POINT 1999
## 24 09001 10200602  PM25-PRI     1.490 POINT 1999
  • fips: A five-digit number (represented as a string) indicating the U.S. county

  • SCC: The name of the source as indicated by a digit string (see source code classification table)

  • Pollutant: A string indicating the pollutant

  • Emissions: Amount of PM2.5 emitted, in tons

  • type: The type of source (point, non-point, on-road, or non-road)

  • year: The year of emissions recorded

Source Classification Code Table (Source_Classification_Code.rds): This table provides a mapping from the SCC digit strings in the Emissions table to the actual name of the PM2.5 source. The sources are categorized in a few different ways from more general to more specific and you may choose to explore whatever categories you think are most useful. For example, source “10100101” is known as “Ext Comb /Electric Gen /Anthracite Coal /Pulverized Coal”.

You can read each of the two files using the readRDS() function in R. For example, reading in each file can be done with the following code:

## This first line will likely take a few seconds. Be patient!
NEI <- readRDS("summarySCC_PM25.rds")
SCC <- readRDS("Source_Classification_Code.rds")

as long as each of those files is in your current working directory (check by calling dir() and see if those files are in the listing).

Assignment

The overall goal of this assignment is to explore the National Emissions Inventory database and see what it say about fine particulate matter pollution in the United states over the 10-year period 1999–2008. You may use any R package you want to support your analysis.

Questions

You must address the following questions and tasks in your exploratory analysis.
For each question/task you will need to make a single plot. Unless specified, you can use any plotting system in R to make your plot.

  1. Have total emissions from PM2.5 decreased in the United States from 1999 to 2008? Using the base plotting system, make a plot showing the total PM2.5 emission from all sources for each of the years 1999, 2002, 2005, and 2008.

  2. Have total emissions from PM2.5 decreased in the Baltimore City, Maryland (fips == "24510") from 1999 to 2008? Use the base plotting system to make a plot answering this question.

  3. Of the four types of sources indicated by the type (point, nonpoint, onroad, nonroad) variable, [Q] which of these four sources have seen decreases in emissions from 1999–2008 for Baltimore City?

    • [Q] Which have seen increases in emissions from 1999–2008? Use the ggplot2 plotting system to make a plot answer this question.
  4. Across the United States, how have emissions from coal combustion-related sources changed from 1999–2008?

  5. How have emissions from motor vehicle sources changed from 1999–2008 in Baltimore City?

  6. Compare emissions from motor vehicle sources in Baltimore City with emissions from motor vehicle sources in Los Angeles County, California (fips == “06037”). [Q] Which city has seen greater changes over time in motor vehicle emissions?

Marking and Submitting Plot

For each plot you should…

  1. Construct the plot and save it to a PNG file.

  2. Create a separate R code file ( plot1.R, plot2.R, etc.) that constructs the corresponding plot, i.e. code in plot1.R constructs the plot1.png plot. Your code file should include code for reading the data so that the plot can be fully reproduced. You must also include the code that creates the PNG file. Only include the code for a single plot (i.e. plot1.R should only include code for producing plot1.png)

  3. Upload the PNG file on the Assignment submission page

  4. Copy and paste the R code from the corresponding R file into the text box at the appropriate point in the peer assessment.

Exploratory Date Analysis

summarySCC_PM25.rds was stored in variable NEI, let’s do some exploration

head(NEI)
##     fips      SCC Pollutant Emissions  type year
## 4  09001 10100401  PM25-PRI    15.714 POINT 1999
## 8  09001 10100404  PM25-PRI   234.178 POINT 1999
## 12 09001 10100501  PM25-PRI     0.128 POINT 1999
## 16 09001 10200401  PM25-PRI     2.036 POINT 1999
## 20 09001 10200504  PM25-PRI     0.388 POINT 1999
## 24 09001 10200602  PM25-PRI     1.490 POINT 1999
names(NEI)
## [1] "fips"      "SCC"       "Pollutant" "Emissions" "type"      "year"
str(NEI)
## 'data.frame':    6497651 obs. of  6 variables:
##  $ fips     : chr  "09001" "09001" "09001" "09001" ...
##  $ SCC      : chr  "10100401" "10100404" "10100501" "10200401" ...
##  $ Pollutant: chr  "PM25-PRI" "PM25-PRI" "PM25-PRI" "PM25-PRI" ...
##  $ Emissions: num  15.714 234.178 0.128 2.036 0.388 ...
##  $ type     : chr  "POINT" "POINT" "POINT" "POINT" ...
##  $ year     : int  1999 1999 1999 1999 1999 1999 1999 1999 1999 1999 ...
head(SCC)
##        SCC Data.Category
## 1 10100101         Point
## 2 10100102         Point
## 3 10100201         Point
## 4 10100202         Point
## 5 10100203         Point
## 6 10100204         Point
##                                                                   Short.Name
## 1                   Ext Comb /Electric Gen /Anthracite Coal /Pulverized Coal
## 2 Ext Comb /Electric Gen /Anthracite Coal /Traveling Grate (Overfeed) Stoker
## 3       Ext Comb /Electric Gen /Bituminous Coal /Pulverized Coal: Wet Bottom
## 4       Ext Comb /Electric Gen /Bituminous Coal /Pulverized Coal: Dry Bottom
## 5                   Ext Comb /Electric Gen /Bituminous Coal /Cyclone Furnace
## 6                   Ext Comb /Electric Gen /Bituminous Coal /Spreader Stoker
##                                EI.Sector Option.Group Option.Set
## 1 Fuel Comb - Electric Generation - Coal                        
## 2 Fuel Comb - Electric Generation - Coal                        
## 3 Fuel Comb - Electric Generation - Coal                        
## 4 Fuel Comb - Electric Generation - Coal                        
## 5 Fuel Comb - Electric Generation - Coal                        
## 6 Fuel Comb - Electric Generation - Coal                        
##                 SCC.Level.One       SCC.Level.Two               SCC.Level.Three
## 1 External Combustion Boilers Electric Generation               Anthracite Coal
## 2 External Combustion Boilers Electric Generation               Anthracite Coal
## 3 External Combustion Boilers Electric Generation Bituminous/Subbituminous Coal
## 4 External Combustion Boilers Electric Generation Bituminous/Subbituminous Coal
## 5 External Combustion Boilers Electric Generation Bituminous/Subbituminous Coal
## 6 External Combustion Boilers Electric Generation Bituminous/Subbituminous Coal
##                                  SCC.Level.Four Map.To Last.Inventory.Year
## 1                               Pulverized Coal     NA                  NA
## 2             Traveling Grate (Overfeed) Stoker     NA                  NA
## 3 Pulverized Coal: Wet Bottom (Bituminous Coal)     NA                  NA
## 4 Pulverized Coal: Dry Bottom (Bituminous Coal)     NA                  NA
## 5             Cyclone Furnace (Bituminous Coal)     NA                  NA
## 6             Spreader Stoker (Bituminous Coal)     NA                  NA
##   Created_Date Revised_Date Usage.Notes
## 1                                      
## 2                                      
## 3                                      
## 4                                      
## 5                                      
## 6
str(SCC)
## 'data.frame':    11717 obs. of  15 variables:
##  $ SCC                : Factor w/ 11717 levels "10100101","10100102",..: 1 2 3 4 5 6 7 8 9 10 ...
##  $ Data.Category      : Factor w/ 6 levels "Biogenic","Event",..: 6 6 6 6 6 6 6 6 6 6 ...
##  $ Short.Name         : Factor w/ 11238 levels "","2,4-D Salts and Esters Prod /Process Vents, 2,4-D Recovery: Filtration",..: 3283 3284 3293 3291 3290 3294 3295 3296 3292 3289 ...
##  $ EI.Sector          : Factor w/ 59 levels "Agriculture - Crops & Livestock Dust",..: 18 18 18 18 18 18 18 18 18 18 ...
##  $ Option.Group       : Factor w/ 25 levels "","C/I Kerosene",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ Option.Set         : Factor w/ 18 levels "","A","B","B1A",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ SCC.Level.One      : Factor w/ 17 levels "Brick Kilns",..: 3 3 3 3 3 3 3 3 3 3 ...
##  $ SCC.Level.Two      : Factor w/ 146 levels "","Agricultural Chemicals Production",..: 32 32 32 32 32 32 32 32 32 32 ...
##  $ SCC.Level.Three    : Factor w/ 1061 levels "","100% Biosolids (e.g., sewage sludge, manure, mixtures of these matls)",..: 88 88 156 156 156 156 156 156 156 156 ...
##  $ SCC.Level.Four     : Factor w/ 6084 levels "","(NH4)2 SO4 Acid Bath System and Evaporator",..: 4455 5583 4466 4458 1341 5246 5584 5983 4461 776 ...
##  $ Map.To             : num  NA NA NA NA NA NA NA NA NA NA ...
##  $ Last.Inventory.Year: int  NA NA NA NA NA NA NA NA NA NA ...
##  $ Created_Date       : Factor w/ 57 levels "","1/27/2000 0:00:00",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ Revised_Date       : Factor w/ 44 levels "","1/27/2000 0:00:00",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ Usage.Notes        : Factor w/ 21 levels ""," ","includes bleaching towers, washer hoods, filtrate tanks, vacuum pump exhausts",..: 1 1 1 1 1 1 1 1 1 1 ...
length(unique(NEI$fips))
## [1] 3263
length(unique(NEI$Pollutant))
## [1] 1

we see a bunch of stuff, also there is only 1 type of pollutant, probably can drop this column, but we will keep it for now

let’s check how many type of measurement are there, the instructions said we should get 4

length(unique(NEI$type))
## [1] 4
# 4 type of measurement

we do get 4 types, what are they?

unique(NEI$type)
## [1] "POINT"    "NONPOINT" "ON-ROAD"  "NON-ROAD"
## [1] "POINT"    "NONPOINT" "ON-ROAD"  "NON-ROAD"

exactly as told, and the years? should see 1999, 2002, 2005, 2008

unique(NEI$year)
## [1] 1999 2002 2005 2008
## [1] 1999 2002 2005 2008

Question 1

Have total emissions from PM2.5 decreased in the United States from 1999 to 2008?

dat <- tapply(NEI$Emissions,NEI$year, FUN = sum)
plot(names(dat), dat,
     type = "b",
     main="PM2.5 Emission from all sources over years", 
     sub="see dreceases in Emission from 1999 to 2008",
     xlab="Year", 
     ylab="Total Emission [ton]")

#dev.copy(png,"plot1.png", width=480, height=480)
#dev.off()

Answer 1

looks like the emission decreases from 1999 to 2008

Question 2

Have total emissions from PM2.5 decreased in the Baltimore City, Maryland (fips == “24510”) from 1999 to 2008?

dat <- subset(NEI, fips == "24510") 
dat <- tapply(dat$Emission, as.factor(dat$year), FUN = sum)
plot(names(dat), dat,
          type = "b",
          main="PM2.5 Emission VS Year, in Baltimore City, Maryland \n total PM2.5 emission from all sources over years", 
          sub="",
          xlab="Year", 
          ylab="Total Emission [ton]"
)

#dev.copy(png,"plot2.png", width=480, height=480)
#dev.off()

Answer 2

overall, pm2.5 emission in Baltimore decrease from 1999 to 2008, with a bump up on 2002-2005 save plot, or not, your choice

Question 3

Of the four types of sources indicated by the type (point, nonpoint, onroad, nonroad) variable, which of these four sources have seen decreases in emissions from 1999–2008 for Baltimore City? Which have seen increases in emissions from 1999–2008?

## Use the ggplot2 plotting system to make a plot answer this question.

dat <- subset(NEI, fips == "24510")
dat <- aggregate(dat$Emissions,
                 by = list(year = dat$year, type = dat$type),
                 FUN = sum)
names(dat)[3] <- "Emissions"
require(ggplot2)
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 4.2.3
ggplot(data = dat, aes(x=year, y=Emissions, group = type, color=type)) +
    geom_point() +
    geom_line() +
    labs(title = "PM2.5 Emission by type of Source",
         subtitle = "source type ON-ROAD, NON-ROAD, and NON-POINT see decreases \n in emission while source type POINT sees increases"
    ) +
    ylab("Total Emission [ton]")

#dev.copy(png,"plot3.png", width=480, height=480)
#dev.off()

Answer 3

3 type of sources, NON-ROAD, ON-ROAD, and NON-POINT see decreases in emission, only POINT source show increases in emission of pm2.5

## all type decrease, except type: POINT, which increase 
dat[(dat$year == 1999 | dat$year == 2008) & dat$type == "POINT",]
##    year  type Emissions
## 13 1999 POINT  296.7950
## 16 2008 POINT  344.9752

PM2.5 from type:POINT increases from 296.7950 tons in 1999 to 344.9752 ton in 2008

Question 4

Across the United States, how have emissions from coal combustion-related sources changed from 1999–2008?

First we need to identify which row correspond to ‘coal-combustion-related’, we can use column NEI$SCC for that, but we will need to find out which SCC code correspond to what we want. We can look at the table SCC to find out which SCC code refers to ‘coal-combustion related sources’

let’s look at dimensions of SCC table

dim(SCC)
## [1] 11717    15

we are working with 15 columns, which of these can help us identify ‘coal-combustion-related sources’? Let’s look at any column that contains the str ‘coal’ anwhere in its value

## find which columns in SCC contains the word 'coal'
co <- integer(15)
for (i in 1:15){
    co[i] <- length(grep("[c,C]oal", SCC[,i]))
}
co
##  [1]   0   0 239  99   0   0   0   0 181 126   0   0   0   0   0

there are 4 columns that contains the string ‘coal’ somewhere in its values, let’s look at the column names,

names(SCC)[co > 0]
## [1] "Short.Name"      "EI.Sector"       "SCC.Level.Three" "SCC.Level.Four"
## [1] "Short.Name"      "EI.Sector"       "SCC.Level.Three" "SCC.Level.Four" 

we want coal combustion and Short.Name look promising, with 239 entries, let’s look at those

tmp <- SCC$Short.Name[grep("[C,c]oal", SCC$Short.Name)]
tmp
##   [1] Ext Comb /Electric Gen /Anthracite Coal /Pulverized Coal                                              
##   [2] Ext Comb /Electric Gen /Anthracite Coal /Traveling Grate (Overfeed) Stoker                            
##   [3] Ext Comb /Electric Gen /Bituminous Coal /Pulverized Coal: Wet Bottom                                  
##   [4] Ext Comb /Electric Gen /Bituminous Coal /Pulverized Coal: Dry Bottom                                  
##   [5] Ext Comb /Electric Gen /Bituminous Coal /Cyclone Furnace                                              
##   [6] Ext Comb /Electric Gen /Bituminous Coal /Spreader Stoker                                              
##   [7] Ext Comb /Electric Gen /Bituminous Coal /Traveling Grate (Overfeed) Stoker                            
##   [8] Ext Comb /Electric Gen /Bituminous Coal /Wet Bottom (Tangential)                                      
##   [9] Ext Comb /Electric Gen /Bituminous Coal /Pulverized Coal: Dry Bottom (Tangential)                     
##  [10] Ext Comb /Electric Gen /Bituminous Coal /Cell Burner                                                  
##  [11] Ext Comb /Electric Gen /Bituminous Coal /Atmospheric Fluidized Bed Combustion: Bubbling Bed           
##  [12] Ext Comb /Electric Gen /Bituminous Coal /Atmospheric Fluidized Bed Combustion: Circulating Bed        
##  [13] Ext Comb /Electric Gen /Subbituminous Coal /Pulverized Coal: Wet Bottom                               
##  [14] Ext Comb /Electric Gen /Subbituminous Coal /Pulverized Coal: Dry Bottom                               
##  [15] Ext Comb /Electric Gen /Subbituminous Coal /Cyclone Furnace                                           
##  [16] Ext Comb /Electric Gen /Subbituminous Coal /Spreader Stoker                                           
##  [17] Ext Comb /Electric Gen /Subbituminous Coal /Traveling Grate (Overfeed) Stoker                         
##  [18] Ext Comb /Electric Gen /Subbituminous Coal /Pulverized Coal: Dry Bottom Tangential                    
##  [19] Ext Comb /Electric Gen /Subbituminous Coal /Cell Burner                                               
##  [20] Ext Comb /Electric Gen /Subbituminous Coal /Atmospheric Fluidized Bed Combustion: Bubbling Bed        
##  [21] Ext Comb /Electric Gen /Subbituminous Coal /Atmospheric Fluidized Bed Combustion - Circulating Bed    
##  [22] Ext Comb /Electric Gen /Lignite /Pulverized Coal: Wet Bottom                                          
##  [23] Ext Comb /Electric Gen /Lignite /Pulverized Coal: Dry Bottom, Wall Fired                              
##  [24] Ext Comb /Electric Gen /Lignite /Pulverized Coal: Dry Bottom, Tangential Fired                        
##  [25] Ext Comb /Electric Gen /Coal-based Synfuel /All                                                       
##  [26] Ext Comb /Electric Gen /Waste Coal /All                                                               
##  [27] Ext Comb /Electric Gen /Waste Coal /Circulating Fluidized Bed                                         
##  [28] Ext Comb /Industrial /Anthracite Coal /Pulverized Coal                                                
##  [29] Ext Comb /Industrial /Anthracite Coal /Traveling Grate (Overfeed) Stoker                              
##  [30] Ext Comb /Industrial /Anthracite Coal /Hand-fired                                                     
##  [31] Ext Comb /Industrial /Anthracite Coal /Fluidized Bed Boiler Burning Anthracite-Culm Fuel              
##  [32] Ext Comb /Industrial /Bitum/Subbit Coal /Pulverized Coal: Wet Bottom                                  
##  [33] Ext Comb /Industrial /Bitum/Subbit Coal /Pulverized Coal: Dry Bottom                                  
##  [34] Ext Comb /Industrial /Bitum/Subbit Coal /Cyclone Furnace                                              
##  [35] Ext Comb /Industrial /Bitum/Subbit Coal /Spreader Stoker                                              
##  [36] Ext Comb /Industrial /Bitum/Subbit Coal /Overfeed Stoker                                              
##  [37] Ext Comb /Industrial /Bitum/Subbit Coal /Underfeed Stoker                                             
##  [38] Ext Comb /Industrial /Bitum/Subbit Coal /Overfeed Stoker **                                           
##  [39] Ext Comb /Industrial /Bitum/Subbit Coal /Pulverized Coal: Dry Bottom (Tangential)                     
##  [40] Ext Comb /Industrial /Bitum/Subbit Coal /Wet Slurry                                                   
##  [41] Ext Comb /Industrial /Bituminous Coal /Atmospheric Fluidized Bed Combustion: Bubbling Bed             
##  [42] Ext Comb /Industrial /Bituminous Coal /Atmospheric Fluidized Bed Combustion: Circulating Bed          
##  [43] Ext Comb /Industrial /Bituminous Coal /Cogeneration                                                   
##  [44] Ext Comb /Industrial /Subbituminous Coal /Pulverized Coal: Wet Bottom                                 
##  [45] Ext Comb /Industrial /Subbituminous Coal /Pulverized Coal: Dry Bottom                                 
##  [46] Ext Comb /Industrial /Subbituminous Coal /Cyclone Furnace                                             
##  [47] Ext Comb /Industrial /Subbituminous Coal /Spreader Stoker                                             
##  [48] Ext Comb /Industrial /Subbituminous Coal /Traveling Grate (Overfeed) Stoker                           
##  [49] Ext Comb /Industrial /Subbituminous Coal /Pulverized Coal: Dry Bottom Tangential                      
##  [50] Ext Comb /Industrial /Subbituminous Coal /Cogeneration                                                
##  [51] Ext Comb /Industrial /Lignite /Pulverized Coal: Wet Bottom                                            
##  [52] Ext Comb /Industrial /Lignite /Pulverized Coal: Dry Bottom, Wall Fired                                
##  [53] Ext Comb /Industrial /Lignite /Pulverized Coal: Dry Bottom, Tangential Fired                          
##  [54] Ext Comb /Comm-Inst /Anthracite Coal /Pulverized Coal                                                 
##  [55] Ext Comb /Comm-Inst /Anthracite Coal /Traveling Grate (Overfeed) Stoker                               
##  [56] Ext Comb /Comm-Inst /Anthracite Coal /Hand-fired                                                      
##  [57] Ext Comb /Comm-Inst /Bituminous Coal /Cyclone Furnace                                                 
##  [58] Ext Comb /Comm-Inst /Bituminous Coal /Pulverized Coal: Wet Bottom                                     
##  [59] Ext Comb /Comm-Inst /Bituminous Coal /Pulverized Coal: Dry Bottom                                     
##  [60] Ext Comb /Comm-Inst /Bituminous Coal /Overfeed Stoker                                                 
##  [61] Ext Comb /Comm-Inst /Bituminous Coal /Underfeed Stoker                                                
##  [62] Ext Comb /Comm-Inst /Bituminous Coal /Spreader Stoker                                                 
##  [63] Ext Comb /Comm-Inst /Bitum/Subbit Coal /Overfeed Stoker **                                            
##  [64] Ext Comb /Comm-Inst /Bituminous Coal /Hand-fired                                                      
##  [65] Ext Comb /Comm-Inst /Bituminous Coal /Pulverized Coal: Dry Bottom (Tangential)                        
##  [66] Ext Comb /Comm-Inst /Bituminous Coal /Atmospheric Fluidized Bed Combustion: Bubbling Bed              
##  [67] Ext Comb /Comm-Inst /Bituminous Coal /Atmospheric Fluidized Bed Combustion: Circulating Bed           
##  [68] Ext Comb /Comm-Inst /Subbituminous Coal /Pulverized Coal: Wet Bottom                                  
##  [69] Ext Comb /Comm-Inst /Subbituminous Coal /Pulverized Coal: Dry Bottom                                  
##  [70] Ext Comb /Comm-Inst /Subbituminous Coal /Cyclone Furnace                                              
##  [71] Ext Comb /Comm-Inst /Subbituminous Coal /Spreader Stoker                                              
##  [72] Ext Comb /Comm-Inst /Subbituminous Coal /Traveling Grate (Overfeed) Stoker                            
##  [73] Ext Comb /Comm-Inst /Subbituminous Coal /Pulverized Coal: Dry Bottom Tangential                       
##  [74] Ext Comb /Comm-Inst /Lignite /Pulverized Coal: Wet Bottom                                             
##  [75] Ext Comb /Comm-Inst /Lignite /Pulverized Coal: Dry Bottom, Wall Fired                                 
##  [76] Ext Comb /Comm-Inst /Lignite /Pulverized Coal: Dry Bottom, Tangential Fired                           
##  [77] Ext Comb /Space Heater /Industrial /Coal **                                                           
##  [78] Ext Comb /Space Heater /Comm-Inst /Coal **                                                            
##  [79] Int Comb /Electric Gen /Gasified Coal /Turbine                                                        
##  [80] Stationary Fuel Comb /Electric Utility /Anthracite Coal /Total: All Boiler Types                      
##  [81] Stationary Fuel Comb /Electric Utility /Bituminous/Subbituminous Coal /Total: All Boiler Types        
##  [82] Stationary Fuel Comb /Electric Utility /Lignite Coal /Total: All Boiler Types                         
##  [83] Stationary Fuel Comb /Industrial /Anthracite Coal /Total: All Boiler Types                            
##  [84] Stationary Fuel Comb /Industrial /Bituminous/Subbituminous Coal /Total: All Boiler Types              
##  [85] Stationary Fuel Comb /Commercial/Institutional /Anthracite Coal /Total: All Boiler Types              
##  [86] Stationary Fuel Comb /Commercial/Institutional /Bituminous/Subbituminous Coal /Total: All Boiler Types
##  [87] Stationary Fuel Comb /Residential /Anthracite Coal /Total: All Combustor Types                        
##  [88] Stationary Fuel Comb /Residential /Bituminous/Subbituminous Coal /Total: All Combustor Types          
##  [89] Stationary Fuel Comb /Total Area Source /Anthracite Coal /Total: All Boiler Types                     
##  [90] Stationary Fuel Comb /Total Area Source /Bituminous/Subbituminous Coal /Total: All Boiler Types       
##  [91] Stationary Fuel Comb /Total Area Source /Lignite Coal /Total: All Boiler Types                        
##  [92] Marine Vessels, Commercial /Coal /Total, All Vessel Types                                             
##  [93] Marine Vessels, Commercial /Coal /Ocean-going Vessels                                                 
##  [94] Marine Vessels, Commercial /Coal /Harbor Vessels                                                      
##  [95] Marine Vessels, Commercial /Coal /Fishing Vessels                                                     
##  [96] Marine Vessels, Commercial /Coal /Military Vessels                                                    
##  [97] Coal Bed Methane NG / Dewatering Pump Engines                                                         
##  [98] Coal Bed Methane NG / Pneumatic Devices                                                               
##  [99] Coal Bed Methane NG / Pneumatic Pumps                                                                 
## [100] Coal Bed Methane NG / Dehydrators                                                                     
## [101] Coal Bed Methane NG / Amine Units                                                                     
## [102] Coal Bed Methane NG / Fugitives                                                                       
## [103] Coal Bed Methane NG / Venting - Initial Completions                                                   
## [104] Coal Bed Methane NG / Venting - Recompletions                                                         
## [105] Coal Bed Methane NG / Venting - Blowdowns                                                             
## [106] Coal Bed Methane NG / Venting - Compressor Startup                                                    
## [107] Coal Bed Methane NG / Venting - Compressor Shutdown                                                   
## [108] In-process Fuel Use /Anthracite Coal /Total                                                           
## [109] In-process Fuel Use /Bituminous/Subbituminous Coal /Total                                             
## [110] Bulk Materials Storage /All Storage Types /Coal                                                       
## [111] Bulk Materials Storage /Commercial/Industrial /Coal                                                   
## [112] Bulk Materials Storage /Bulk Stations/Terminals /Coal                                                 
## [113] Bulk Materials Transport /All Transport Types /Coal                                                   
## [114] Bulk Materials Transport /Rail Car /Coal                                                              
## [115] Bulk Materials Transport /Marine Vessel /Coal                                                         
## [116] Bulk Materials Transport /Truck /Coal                                                                 
## [117] Charcoal Grilling - Residential /Total                                                                
## [118] Chem Manuf /Charcoal Manuf /General                                                                   
## [119] Chem Manuf /Charcoal Manuf /Batch Kiln                                                                
## [120] Chem Manuf /Charcoal Manuf /Continuous Kiln                                                           
## [121] Chem Manuf /Charcoal Manuf /Briquetting                                                               
## [122] Chem Manuf /Charcoal Manuf /Raw Material Handling                                                     
## [123] Chem Manuf /Charcoal Manuf /Crushing                                                                  
## [124] Chem Manuf /Charcoal Manuf /Handling and Storage                                                      
## [125] Chem Manuf /Charcoal Manuf /Other Not Classified                                                      
## [126] Chem Manuf /Sodium Carbonate /Monohydrate Process: Rotary Ore Calciner: Coal-fired                    
## [127] Alfalfa Dehydration /Coal-fired, Triple-Pass Dryer Cyclone                                            
## [128] Sugar Beet Processing /Pulp Dryer : Coal-fired                                                        
## [129] Sugar Beet Processing /Lime Kiln : Coal-fired                                                         
## [130] By-product Coke Manuf /Coal Unloading                                                                 
## [131] By-product Coke Manuf /Coal Crushing/Handling                                                         
## [132] By-product Coke Manuf /Coal Conveying                                                                 
## [133] By-product Coke Manuf /Coal Crushing                                                                  
## [134] By-product Coke Manuf /Coal Screening                                                                 
## [135] By-product Coke Manuf /Coal Preheater                                                                 
## [136] By-product Coke Manuf /Coal Storage Pile                                                              
## [137] Integr Iron&Steel Manuf /Pile Formation Stacker: Coal                                                 
## [138] Taconite Iron Ore Processing /Indurating Furnace: Coal Fired** (see 3-03-023-51 thru -88)             
## [139] Taconite Iron Ore Processing /Induration: Grate/Kiln, Coke & Coal-fired, Acid Pellets                 
## [140] Taconite Iron Ore Processing /Induration: Grate/Kiln, Coke & Coal-fired, Flux Pellets                 
## [141] Taconite Iron Ore Processing /Induration: Grate/Kiln, Coal-fired, Acid Pellets                        
## [142] Taconite Iron Ore Processing /Induration: Grate/Kiln, Coal-fired, Flux Pellets                        
## [143] Taconite Iron Ore Processing /Induration: Grate/Kiln, Coal & Oil-fired, Acid Pellets                  
## [144] Taconite Iron Ore Processing /Induration: Grate/Kiln, Coal & Oil-fired, Flux Pellets                  
## [145] Secondary Metals /Furnace Electrode Manuf /Grafitization of Coal by Heating Process                   
## [146] Brick Manuf /Curing and Firing: Coal-fired Tunnel Kilns                                               
## [147] Brick Manuf /Curing and Firing: Coal-fired Periodic Kilns                                             
## [148] Brick Manuf /Curing and Firing: Coal-fired Kiln, Other Type                                           
## [149] Brick Manuf /Coal Crushing And Storage System                                                         
## [150] Cement Manuf (Dry Proc) /Pulverized Coal Kiln Feed Units                                              
## [151] Coal Mining, Cleaning & Material Handling /Fluidized Bed                                              
## [152] Coal Mining, Cleaning & Material Handling /Flash or Suspension                                        
## [153] Coal Mining, Cleaning & Material Handling /Multilouvered                                              
## [154] Coal Mining, Cleaning & Material Handling /Rotary                                                     
## [155] Coal Mining, Cleaning & Material Handling /Cascade                                                    
## [156] Coal Mining, Cleaning & Material Handling /Continuous Carrier                                         
## [157] Coal Mining, Cleaning & Material Handling /Screen                                                     
## [158] Coal Mining, Cleaning & Material Handling /Unloading                                                  
## [159] Coal Mining, Cleaning & Material Handling /Raw Coal Storage                                           
## [160] Coal Mining, Cleaning & Material Handling /Crushing                                                   
## [161] Coal Mining, Cleaning & Material Handling /Coal Transfer                                              
## [162] Coal Mining, Cleaning & Material Handling /Screening                                                  
## [163] Coal Mining, Cleaning & Material Handling /Air Tables                                                 
## [164] Coal Mining, Cleaning & Material Handling /Cleaned Coal Storage                                       
## [165] Coal Mining, Cleaning & Material Handling /Loading                                                    
## [166] Coal Mining, Cleaning & Material Handling /Loading: Clean Coal                                        
## [167] Coal Mining, Cleaning & Material Handling /Secondary Crushing                                         
## [168] Coal Mining, Cleaning & Material Handling /Overburden Removal                                         
## [169] Coal Mining, Cleaning & Material Handling /Drilling/Blasting                                          
## [170] Coal Mining, Cleaning & Material Handling /Loading                                                    
## [171] Coal Mining, Cleaning & Material Handling /Hauling                                                    
## [172] Coal Mining, Cleaning & Material Handling /Topsoil Removal                                            
## [173] Coal Mining, Cleaning & Material Handling /Scrapers: Travel Mode                                      
## [174] Coal Mining, Cleaning & Material Handling /Topsoil Unloading                                          
## [175] Coal Mining, Cleaning & Material Handling /Overburden                                                 
## [176] Coal Mining, Cleaning & Material Handling /Coal Seam: Drilling                                        
## [177] Coal Mining, Cleaning & Material Handling /Blasting: Coal Overburden                                  
## [178] Coal Mining, Cleaning & Material Handling /Dragline: Overburden Removal                               
## [179] Coal Mining, Cleaning & Material Handling /Truck Loading: Overburden                                  
## [180] Coal Mining, Cleaning & Material Handling /Truck Loading: Coal                                        
## [181] Coal Mining, Cleaning & Material Handling /Hauling: Haul Trucks                                       
## [182] Coal Mining, Cleaning & Material Handling /Truck Unloading: End Dump - Coal                           
## [183] Coal Mining, Cleaning & Material Handling /Truck Unloading: Bottom Dump - Coal                        
## [184] Coal Mining, Cleaning & Material Handling /Truck Unloading: Bottom Dump - Overburden                  
## [185] Coal Mining, Cleaning & Material Handling /Open Storage Pile: Coal                                    
## [186] Coal Mining, Cleaning & Material Handling /Train Loading: Coal                                        
## [187] Coal Mining, Cleaning & Material Handling /Bulldozing: Overburden                                     
## [188] Coal Mining, Cleaning & Material Handling /Bulldozing: Coal                                           
## [189] Coal Mining, Cleaning & Material Handling /Grading                                                    
## [190] Coal Mining, Cleaning & Material Handling /Overburden Replacement                                     
## [191] Coal Mining, Cleaning & Material Handling /Wind Erosion: Exposed Areas                                
## [192] Coal Mining, Cleaning & Material Handling /Vehicle Traffic: Light/Medium Vehicles                     
## [193] Coal Mining, Cleaning & Material Handling /Surface Mining Operations: Open Storage Pile: Spoils       
## [194] Coal Mining, Cleaning & Material Handling /Surface Mining Operations: Primary Crusher                 
## [195] Coal Mining, Cleaning & Material Handling /Surface Mining Operations: Secondary Crusher               
## [196] Coal Mining, Cleaning & Material Handling /Surface Mining Operations: Screens                         
## [197] Coal Mining, Cleaning & Material Handling /Haul Roads: General                                        
## [198] Coal Mining, Cleaning & Material Handling /Other Not Classified                                       
## [199] Lime Manuf /Calcining: Coal-fired Rotary Kiln                                                         
## [200] Lime Manuf /Calcining: Coal- and Gas-fired Rotary Kiln                                                
## [201] Lime Manuf /Calcining: Coal- and Coke-fired Rotary Kiln                                               
## [202] Lime Manuf /Calcining: Coal-fired Rotary Preheater Kiln                                               
## [203] Mineral Prods /Bulk Materials Conveyors /Coal                                                         
## [204] Mineral Prods /Bulk Materials Storage Bins /Coal                                                      
## [205] Mineral Prods /Bulk Materials Open Stockpiles /Coal                                                   
## [206] Mineral Prods /Bulk Materials Unloading Op /Coal                                                      
## [207] Mineral Prods /Bulk Materials Loading  /Coal                                                          
## [208] Coal Mining, Cleaning & Material Handling /Fluidized Bed                                              
## [209] Coal Mining, Cleaning & Material Handling /Flash or Suspension                                        
## [210] Coal Mining, Cleaning & Material Handling /Multilouvered                                              
## [211] Coal Mining, Cleaning & Material Handling /Rotary                                                     
## [212] Coal Mining, Cleaning & Material Handling /Cascade                                                    
## [213] Coal Mining, Cleaning & Material Handling /Continuous Carrier                                         
## [214] Coal Mining, Cleaning & Material Handling /Screen                                                     
## [215] Coal Mining, Cleaning & Material Handling /Unloading                                                  
## [216] Coal Mining, Cleaning & Material Handling /Raw Coal Storage                                           
## [217] Coal Mining, Cleaning & Material Handling /Crushing                                                   
## [218] Coal Mining, Cleaning & Material Handling /Coal Transfer                                              
## [219] Coal Mining, Cleaning & Material Handling /Screening                                                  
## [220] Coal Mining, Cleaning & Material Handling /Air Tables                                                 
## [221] Coal Mining, Cleaning & Material Handling /Cleaned Coal Storage                                       
## [222] Coal Mining, Cleaning & Material Handling /Loading                                                    
## [223] Coal Mining, Cleaning & Material Handling /Loading: Clean Coal                                        
## [224] Coal Mining, Cleaning & Material Handling /Secondary Crushing                                         
## [225] Coal Mining, Cleaning & Material Handling /Haul Roads: General                                        
## [226] Coal Mining, Cleaning & Material Handling /Other Not Classified                                       
## [227] Fabricated Metal /Metal Pipe Coating of Metal Parts /Coal Tar/Asphalt Melting Kettle                  
## [228] Fabricated Metal /Metal Pipe Coating of Metal Parts /Raw Material Storage: Coal Tar                   
## [229] In-Process Fuel Use /Anthracite Coal /General                                                         
## [230] In-Process Fuel Use /Anthracite Coal /General                                                         
## [231] In-Process Fuel Use /Bituminous Coal /Cement Kiln/Dryer                                               
## [232] In-Process Fuel Use /Bituminous Coal /Lime Kiln                                                       
## [233] In-Process Fuel Use /Subbituminous Coal /General                                                      
## [234] In-Process Fuel Use /Bituminous Coal /General                                                         
## [235] In-Process Fuel Use /Bituminous Coal /General                                                         
## [236] Waste Disp-Govt /Auxillary Fuel-No Emissions /Coal                                                    
## [237] Waste Disp-Comm-Inst /Auxillary Fuel-No Emissions /Coal                                               
## [238] Waste Disp-Indus /Open Burning /Coal Refuse Piles                                                     
## [239] Waste Disp-Indus /Auxillary Fuel-No Emissions /Coal                                                   
## 11238 Levels:  ...

we wanted coal-combustion-related, but these includes coal-transport, coal-by-product, coal-processing and many more, which we need to filter out. Also, the word ‘combustion’ seems to get shorten as Comb instead. We will keep that in mind let’s look at EI.Sector with the word ‘coal’ in them, there are 99 entries

tmp <- SCC$EI.Sector[grep("[C,c]oal", SCC$EI.Sector)]
tmp
##  [1] Fuel Comb - Electric Generation - Coal     
##  [2] Fuel Comb - Electric Generation - Coal     
##  [3] Fuel Comb - Electric Generation - Coal     
##  [4] Fuel Comb - Electric Generation - Coal     
##  [5] Fuel Comb - Electric Generation - Coal     
##  [6] Fuel Comb - Electric Generation - Coal     
##  [7] Fuel Comb - Electric Generation - Coal     
##  [8] Fuel Comb - Electric Generation - Coal     
##  [9] Fuel Comb - Electric Generation - Coal     
## [10] Fuel Comb - Electric Generation - Coal     
## [11] Fuel Comb - Electric Generation - Coal     
## [12] Fuel Comb - Electric Generation - Coal     
## [13] Fuel Comb - Electric Generation - Coal     
## [14] Fuel Comb - Electric Generation - Coal     
## [15] Fuel Comb - Electric Generation - Coal     
## [16] Fuel Comb - Electric Generation - Coal     
## [17] Fuel Comb - Electric Generation - Coal     
## [18] Fuel Comb - Electric Generation - Coal     
## [19] Fuel Comb - Electric Generation - Coal     
## [20] Fuel Comb - Electric Generation - Coal     
## [21] Fuel Comb - Electric Generation - Coal     
## [22] Fuel Comb - Electric Generation - Coal     
## [23] Fuel Comb - Electric Generation - Coal     
## [24] Fuel Comb - Electric Generation - Coal     
## [25] Fuel Comb - Electric Generation - Coal     
## [26] Fuel Comb - Electric Generation - Coal     
## [27] Fuel Comb - Electric Generation - Coal     
## [28] Fuel Comb - Electric Generation - Coal     
## [29] Fuel Comb - Electric Generation - Coal     
## [30] Fuel Comb - Electric Generation - Coal     
## [31] Fuel Comb - Electric Generation - Coal     
## [32] Fuel Comb - Electric Generation - Coal     
## [33] Fuel Comb - Industrial Boilers, ICEs - Coal
## [34] Fuel Comb - Industrial Boilers, ICEs - Coal
## [35] Fuel Comb - Industrial Boilers, ICEs - Coal
## [36] Fuel Comb - Industrial Boilers, ICEs - Coal
## [37] Fuel Comb - Industrial Boilers, ICEs - Coal
## [38] Fuel Comb - Industrial Boilers, ICEs - Coal
## [39] Fuel Comb - Industrial Boilers, ICEs - Coal
## [40] Fuel Comb - Industrial Boilers, ICEs - Coal
## [41] Fuel Comb - Industrial Boilers, ICEs - Coal
## [42] Fuel Comb - Industrial Boilers, ICEs - Coal
## [43] Fuel Comb - Industrial Boilers, ICEs - Coal
## [44] Fuel Comb - Industrial Boilers, ICEs - Coal
## [45] Fuel Comb - Industrial Boilers, ICEs - Coal
## [46] Fuel Comb - Industrial Boilers, ICEs - Coal
## [47] Fuel Comb - Industrial Boilers, ICEs - Coal
## [48] Fuel Comb - Industrial Boilers, ICEs - Coal
## [49] Fuel Comb - Industrial Boilers, ICEs - Coal
## [50] Fuel Comb - Industrial Boilers, ICEs - Coal
## [51] Fuel Comb - Industrial Boilers, ICEs - Coal
## [52] Fuel Comb - Industrial Boilers, ICEs - Coal
## [53] Fuel Comb - Industrial Boilers, ICEs - Coal
## [54] Fuel Comb - Industrial Boilers, ICEs - Coal
## [55] Fuel Comb - Industrial Boilers, ICEs - Coal
## [56] Fuel Comb - Industrial Boilers, ICEs - Coal
## [57] Fuel Comb - Industrial Boilers, ICEs - Coal
## [58] Fuel Comb - Industrial Boilers, ICEs - Coal
## [59] Fuel Comb - Industrial Boilers, ICEs - Coal
## [60] Fuel Comb - Industrial Boilers, ICEs - Coal
## [61] Fuel Comb - Industrial Boilers, ICEs - Coal
## [62] Fuel Comb - Industrial Boilers, ICEs - Coal
## [63] Fuel Comb - Comm/Institutional - Coal      
## [64] Fuel Comb - Comm/Institutional - Coal      
## [65] Fuel Comb - Comm/Institutional - Coal      
## [66] Fuel Comb - Comm/Institutional - Coal      
## [67] Fuel Comb - Comm/Institutional - Coal      
## [68] Fuel Comb - Comm/Institutional - Coal      
## [69] Fuel Comb - Comm/Institutional - Coal      
## [70] Fuel Comb - Comm/Institutional - Coal      
## [71] Fuel Comb - Comm/Institutional - Coal      
## [72] Fuel Comb - Comm/Institutional - Coal      
## [73] Fuel Comb - Comm/Institutional - Coal      
## [74] Fuel Comb - Comm/Institutional - Coal      
## [75] Fuel Comb - Comm/Institutional - Coal      
## [76] Fuel Comb - Comm/Institutional - Coal      
## [77] Fuel Comb - Comm/Institutional - Coal      
## [78] Fuel Comb - Comm/Institutional - Coal      
## [79] Fuel Comb - Comm/Institutional - Coal      
## [80] Fuel Comb - Comm/Institutional - Coal      
## [81] Fuel Comb - Comm/Institutional - Coal      
## [82] Fuel Comb - Comm/Institutional - Coal      
## [83] Fuel Comb - Comm/Institutional - Coal      
## [84] Fuel Comb - Comm/Institutional - Coal      
## [85] Fuel Comb - Comm/Institutional - Coal      
## [86] Fuel Comb - Comm/Institutional - Coal      
## [87] Fuel Comb - Comm/Institutional - Coal      
## [88] Fuel Comb - Industrial Boilers, ICEs - Coal
## [89] Fuel Comb - Comm/Institutional - Coal      
## [90] Fuel Comb - Electric Generation - Coal     
## [91] Fuel Comb - Electric Generation - Coal     
## [92] Fuel Comb - Electric Generation - Coal     
## [93] Fuel Comb - Industrial Boilers, ICEs - Coal
## [94] Fuel Comb - Industrial Boilers, ICEs - Coal
## [95] Fuel Comb - Comm/Institutional - Coal      
## [96] Fuel Comb - Comm/Institutional - Coal      
## [97] Fuel Comb - Comm/Institutional - Coal      
## [98] Fuel Comb - Comm/Institutional - Coal      
## [99] Fuel Comb - Comm/Institutional - Coal      
## 59 Levels: Agriculture - Crops & Livestock Dust ...

there is 99 entries, and all of these have prefix Fuel Comb meaning Fuel Combustion, which is what we want, let’s look at the Short.Name where EI.sector contains the word coal, expected to see only coal combustion related now (since all of them have prefix ‘fuel comb’)

tmp <- SCC$Short.Name[grep("[C,c]oal", SCC$EI.Sector)]
tmp
##  [1] Ext Comb /Electric Gen /Anthracite Coal /Pulverized Coal                                              
##  [2] Ext Comb /Electric Gen /Anthracite Coal /Traveling Grate (Overfeed) Stoker                            
##  [3] Ext Comb /Electric Gen /Bituminous Coal /Pulverized Coal: Wet Bottom                                  
##  [4] Ext Comb /Electric Gen /Bituminous Coal /Pulverized Coal: Dry Bottom                                  
##  [5] Ext Comb /Electric Gen /Bituminous Coal /Cyclone Furnace                                              
##  [6] Ext Comb /Electric Gen /Bituminous Coal /Spreader Stoker                                              
##  [7] Ext Comb /Electric Gen /Bituminous Coal /Traveling Grate (Overfeed) Stoker                            
##  [8] Ext Comb /Electric Gen /Bituminous Coal /Wet Bottom (Tangential)                                      
##  [9] Ext Comb /Electric Gen /Bituminous Coal /Pulverized Coal: Dry Bottom (Tangential)                     
## [10] Ext Comb /Electric Gen /Bituminous Coal /Cell Burner                                                  
## [11] Ext Comb /Electric Gen /Bituminous Coal /Atmospheric Fluidized Bed Combustion: Bubbling Bed           
## [12] Ext Comb /Electric Gen /Bituminous Coal /Atmospheric Fluidized Bed Combustion: Circulating Bed        
## [13] Ext Comb /Electric Gen /Subbituminous Coal /Pulverized Coal: Wet Bottom                               
## [14] Ext Comb /Electric Gen /Subbituminous Coal /Pulverized Coal: Dry Bottom                               
## [15] Ext Comb /Electric Gen /Subbituminous Coal /Cyclone Furnace                                           
## [16] Ext Comb /Electric Gen /Subbituminous Coal /Spreader Stoker                                           
## [17] Ext Comb /Electric Gen /Subbituminous Coal /Traveling Grate (Overfeed) Stoker                         
## [18] Ext Comb /Electric Gen /Subbituminous Coal /Pulverized Coal: Dry Bottom Tangential                    
## [19] Ext Comb /Electric Gen /Subbituminous Coal /Cell Burner                                               
## [20] Ext Comb /Electric Gen /Subbituminous Coal /Atmospheric Fluidized Bed Combustion: Bubbling Bed        
## [21] Ext Comb /Electric Gen /Subbituminous Coal /Atmospheric Fluidized Bed Combustion - Circulating Bed    
## [22] Ext Comb /Electric Gen /Lignite /Pulverized Coal: Wet Bottom                                          
## [23] Ext Comb /Electric Gen /Lignite /Pulverized Coal: Dry Bottom, Wall Fired                              
## [24] Ext Comb /Electric Gen /Lignite /Pulverized Coal: Dry Bottom, Tangential Fired                        
## [25] Ext Comb /Electric Gen /Lignite /Cyclone Furnace                                                      
## [26] Ext Comb /Electric Gen /Lignite /Traveling Grate (Overfeed) Stoker                                    
## [27] Ext Comb /Electric Gen /Lignite /Spreader Stoker                                                      
## [28] Ext Comb /Electric Gen /Lignite /Atmospheric Fluidized Bed ** (See 101003-17 & -18)                   
## [29] Ext Comb /Electric Gen /Lignite /Atmospheric Fluidized Bed Combustion - Bubbling Bed                  
## [30] Ext Comb /Electric Gen /Lignite /Atmospheric Fluidized Bed Combustion - Circulating Bed               
## [31] Ext Comb /Electric Gen /Waste Coal /All                                                               
## [32] Ext Comb /Electric Gen /Waste Coal /Circulating Fluidized Bed                                         
## [33] Ext Comb /Industrial /Anthracite Coal /Pulverized Coal                                                
## [34] Ext Comb /Industrial /Anthracite Coal /Traveling Grate (Overfeed) Stoker                              
## [35] Ext Comb /Industrial /Anthracite Coal /Hand-fired                                                     
## [36] Ext Comb /Industrial /Anthracite Coal /Fluidized Bed Boiler Burning Anthracite-Culm Fuel              
## [37] Ext Comb /Industrial /Bitum/Subbit Coal /Pulverized Coal: Wet Bottom                                  
## [38] Ext Comb /Industrial /Bitum/Subbit Coal /Pulverized Coal: Dry Bottom                                  
## [39] Ext Comb /Industrial /Bitum/Subbit Coal /Cyclone Furnace                                              
## [40] Ext Comb /Industrial /Bitum/Subbit Coal /Spreader Stoker                                              
## [41] Ext Comb /Industrial /Bitum/Subbit Coal /Overfeed Stoker                                              
## [42] Ext Comb /Industrial /Bitum/Subbit Coal /Underfeed Stoker                                             
## [43] Ext Comb /Industrial /Bitum/Subbit Coal /Overfeed Stoker **                                           
## [44] Ext Comb /Industrial /Bitum/Subbit Coal /Pulverized Coal: Dry Bottom (Tangential)                     
## [45] Ext Comb /Industrial /Bitum/Subbit Coal /Wet Slurry                                                   
## [46] Ext Comb /Industrial /Bituminous Coal /Atmospheric Fluidized Bed Combustion: Bubbling Bed             
## [47] Ext Comb /Industrial /Bituminous Coal /Atmospheric Fluidized Bed Combustion: Circulating Bed          
## [48] Ext Comb /Industrial /Bituminous Coal /Cogeneration                                                   
## [49] Ext Comb /Industrial /Subbituminous Coal /Pulverized Coal: Wet Bottom                                 
## [50] Ext Comb /Industrial /Subbituminous Coal /Pulverized Coal: Dry Bottom                                 
## [51] Ext Comb /Industrial /Subbituminous Coal /Cyclone Furnace                                             
## [52] Ext Comb /Industrial /Subbituminous Coal /Spreader Stoker                                             
## [53] Ext Comb /Industrial /Subbituminous Coal /Traveling Grate (Overfeed) Stoker                           
## [54] Ext Comb /Industrial /Subbituminous Coal /Pulverized Coal: Dry Bottom Tangential                      
## [55] Ext Comb /Industrial /Subbituminous Coal /Cogeneration                                                
## [56] Ext Comb /Industrial /Lignite /Pulverized Coal: Wet Bottom                                            
## [57] Ext Comb /Industrial /Lignite /Pulverized Coal: Dry Bottom, Wall Fired                                
## [58] Ext Comb /Industrial /Lignite /Pulverized Coal: Dry Bottom, Tangential Fired                          
## [59] Ext Comb /Industrial /Lignite /Cyclone Furnace                                                        
## [60] Ext Comb /Industrial /Lignite /Traveling Grate (Overfeed) Stoker                                      
## [61] Ext Comb /Industrial /Lignite /Spreader Stoker                                                        
## [62] Ext Comb /Industrial /Lignite /Cogeneration                                                           
## [63] Ext Comb /Comm-Inst /Anthracite Coal /Pulverized Coal                                                 
## [64] Ext Comb /Comm-Inst /Anthracite Coal /Traveling Grate (Overfeed) Stoker                               
## [65] Ext Comb /Comm-Inst /Anthracite Coal /Hand-fired                                                      
## [66] Ext Comb /Comm-Inst /Bituminous Coal /Cyclone Furnace                                                 
## [67] Ext Comb /Comm-Inst /Bituminous Coal /Pulverized Coal: Wet Bottom                                     
## [68] Ext Comb /Comm-Inst /Bituminous Coal /Pulverized Coal: Dry Bottom                                     
## [69] Ext Comb /Comm-Inst /Bituminous Coal /Overfeed Stoker                                                 
## [70] Ext Comb /Comm-Inst /Bituminous Coal /Underfeed Stoker                                                
## [71] Ext Comb /Comm-Inst /Bituminous Coal /Spreader Stoker                                                 
## [72] Ext Comb /Comm-Inst /Bitum/Subbit Coal /Overfeed Stoker **                                            
## [73] Ext Comb /Comm-Inst /Bituminous Coal /Hand-fired                                                      
## [74] Ext Comb /Comm-Inst /Bituminous Coal /Pulverized Coal: Dry Bottom (Tangential)                        
## [75] Ext Comb /Comm-Inst /Bituminous Coal /Atmospheric Fluidized Bed Combustion: Bubbling Bed              
## [76] Ext Comb /Comm-Inst /Bituminous Coal /Atmospheric Fluidized Bed Combustion: Circulating Bed           
## [77] Ext Comb /Comm-Inst /Subbituminous Coal /Pulverized Coal: Wet Bottom                                  
## [78] Ext Comb /Comm-Inst /Subbituminous Coal /Pulverized Coal: Dry Bottom                                  
## [79] Ext Comb /Comm-Inst /Subbituminous Coal /Cyclone Furnace                                              
## [80] Ext Comb /Comm-Inst /Subbituminous Coal /Spreader Stoker                                              
## [81] Ext Comb /Comm-Inst /Subbituminous Coal /Traveling Grate (Overfeed) Stoker                            
## [82] Ext Comb /Comm-Inst /Subbituminous Coal /Pulverized Coal: Dry Bottom Tangential                       
## [83] Ext Comb /Comm-Inst /Lignite /Pulverized Coal: Wet Bottom                                             
## [84] Ext Comb /Comm-Inst /Lignite /Pulverized Coal: Dry Bottom, Wall Fired                                 
## [85] Ext Comb /Comm-Inst /Lignite /Pulverized Coal: Dry Bottom, Tangential Fired                           
## [86] Ext Comb /Comm-Inst /Lignite /Traveling Grate (Overfeed) Stoker                                       
## [87] Ext Comb /Comm-Inst /Lignite /Spreader Stoker                                                         
## [88] Ext Comb /Space Heater /Industrial /Coal **                                                           
## [89] Ext Comb /Space Heater /Comm-Inst /Coal **                                                            
## [90] Stationary Fuel Comb /Electric Utility /Anthracite Coal /Total: All Boiler Types                      
## [91] Stationary Fuel Comb /Electric Utility /Bituminous/Subbituminous Coal /Total: All Boiler Types        
## [92] Stationary Fuel Comb /Electric Utility /Lignite Coal /Total: All Boiler Types                         
## [93] Stationary Fuel Comb /Industrial /Anthracite Coal /Total: All Boiler Types                            
## [94] Stationary Fuel Comb /Industrial /Bituminous/Subbituminous Coal /Total: All Boiler Types              
## [95] Stationary Fuel Comb /Commercial/Institutional /Anthracite Coal /Total: All Boiler Types              
## [96] Stationary Fuel Comb /Commercial/Institutional /Bituminous/Subbituminous Coal /Total: All Boiler Types
## [97] Stationary Fuel Comb /Total Area Source /Anthracite Coal /Total: All Boiler Types                     
## [98] Stationary Fuel Comb /Total Area Source /Bituminous/Subbituminous Coal /Total: All Boiler Types       
## [99] Stationary Fuel Comb /Total Area Source /Lignite Coal /Total: All Boiler Types                        
## 11238 Levels:  ...

all of the Short.Name contains the word ‘comb’ for combustion, also notice that some Short.Name(such as Ext Comb /Electric Gen /Lignite/Spreader Stoker ) does not contain the word coal itself, but contains the word lignite, which is a type of coal. To make sure we don’t miss anything, let’s create 2 conditions: cond1 : must contain the string coal in any column cond2 : must contain the string comb (for Combustion) in any column we want ‘Coal-combustion-related’ therefore, both conditions must be true

cond1 <- integer()
for (col in 1:15){
    cond1 <- union(cond1, grep("[c,C]oal", SCC[,col]))
}
cond2 <- integer()
for (col in 1:15){
    cond2 <- union(cond2, grep("[c,C]omb", SCC[,col]))
}
cond <- intersect(cond1, cond2)
length(cond)
## [1] 104

we got 104 entries, 5 more than the previous 99, let’s see the differences

dff <- setdiff(
    SCC$EI.Sector[cond],
    SCC$EI.Sector[grep("[c,C]oal",SCC$EI.Sector)]
)
dff
## [1] "Fuel Comb - Electric Generation - Other"
## [2] "Fuel Comb - Residential - Other"        
## [3] "Miscellaneous Non-Industrial NEC"

we got ‘Other’ and ‘Miscellaneous’, are these really coal combustion? let’s look at the shortnames

coalCombRelated <- SCC[cond,]
tmp <- coalCombRelated[coalCombRelated$EI.Sector %in% dff,]
tmp$Short.Name
## [1] Ext Comb /Electric Gen /Coal-based Synfuel /All                                             
## [2] Int Comb /Electric Gen /Gasified Coal /Turbine                                              
## [3] Stationary Fuel Comb /Residential /Anthracite Coal /Total: All Combustor Types              
## [4] Stationary Fuel Comb /Residential /Bituminous/Subbituminous Coal /Total: All Combustor Types
## [5] Charcoal Grilling - Residential /Total                                                      
## 11238 Levels:  ...
## [1] Ext Comb /Electric Gen /Coal-based Synfuel /All                                             
## [2] Int Comb /Electric Gen /Gasified Coal /Turbine                                              
## [3] Stationary Fuel Comb /Residential /Anthracite Coal /Total: All Combustor Types              
## [4] Stationary Fuel Comb /Residential /Bituminous/Subbituminous Coal /Total: All Combustor Types
## [5] Charcoal Grilling - Residential /Total  

should we count combustion of Coal-based synthetic fuel? what about residential charcoal grilling? backyard BBQ sure does produce PM2.5, right?

to help decide what to include/exclude, we could try to calculate the effect size of these entries, but for the sake of this assignment I’m gonna just include them, since they all look like “coal-combustion-related”

Back to the Question Q4, how have emissions from coal combustion-related sources changed from 1999–2008 across the US?

dat <- subset(NEI, SCC %in% coalCombRelated$SCC)
dat <- aggregate(dat$Emissions,
                 by = list(year = dat$year),
                 FUN = sum)
names(dat)[2] <- "Emissions"
require(ggplot2)
ggplot(data = dat, aes(x=year, y=Emissions)) +
    geom_point() +
    geom_line() +
    labs(title = "PM2.5 Emissions from Coal Combustion-Related sources") +
    ylab("Total Emissions [ton]")

#dev.copy(png,"plot4.png", width=480, height=480)
#dev.off()

Answer 4

across the US, coal-combustion-related pm2.5 drops sharply in the period between 2005 and 2008

Question 5

How have emissions from motor vehicle sources changed from 1999–2008 in Baltimore City? (note that fips == "24510" for County Baltimore City)

first we need to identify which row in NEI correspond to “motor vehicle sources”, we can look at the NEI$SCC to get the SCC code, then check SCC table which codes are “motor vehicles” let’s look at columns that include string ‘vehi’ (for ‘vehicle’)

condVehi <- integer()
for (col in 1:15){
    condVehi <- union(condVehi, grep("[v,V]ehi", SCC[,col]))
}
length(condVehi)
## [1] 1495
vehiRel <- SCC[condVehi,]
unique(vehiRel$EI.Sector)
##  [1] Mobile - On-Road Gasoline Light Duty Vehicles     
##  [2] Mobile - On-Road Diesel Light Duty Vehicles       
##  [3] Mobile - Non-Road Equipment - Gasoline            
##  [4] Mobile - Non-Road Equipment - Other               
##  [5] Mobile - Non-Road Equipment - Diesel              
##  [6] Dust - Construction Dust                          
##  [7] Solvent - Industrial Surface Coating & Solvent Use
##  [8] Miscellaneous Non-Industrial NEC                  
##  [9] Industrial Processes - Chemical Manuf             
## [10] Industrial Processes - Storage and Transfer       
## [11] Industrial Processes - Mining                     
## [12] Gas Stations                                      
## [13] Mobile - On-Road Gasoline Heavy Duty Vehicles     
## [14] Mobile - On-Road Diesel Heavy Duty Vehicles       
## 59 Levels: Agriculture - Crops & Livestock Dust ...

got 1495 entries, with 14 unique values, now let’s look at “motor vehicle” now let’s look at columns with string ‘motor Vehicle’

condMV <- integer()
for (col in 1:15){
    condMV <- union(condMV, grep("[M,m]otor [v,V]ehicle", SCC[,col]))
}
length(condMV)
## [1] 20
mvRel <- SCC[condMV,]
unique(mvRel$EI.Sector)
## [1] Solvent - Industrial Surface Coating & Solvent Use
## [2] Miscellaneous Non-Industrial NEC                  
## 59 Levels: Agriculture - Crops & Livestock Dust ...

got 20 entries, with 2 unique values: “Solvent” and “Miscellaneous” does not look like motor vehicle as defined in wikipedia we will assume,for the sake of assignment, that ‘motor vehicles’ are on-road only.

now let’s make the plot for Q5, emission from ‘motor vehicle sources’ in Baltimore City

roadVeh <- vehiRel[vehiRel$Data.Category == "Onroad",]
dat <- subset(NEI, SCC %in% roadVeh$SCC & fips == "24510")
dat <- aggregate(dat$Emissions,
                 by = list(year = dat$year),
                 FUN = sum)
names(dat)[2] <- "Emissions"
require(ggplot2)
ggplot(data = dat, aes(x=year, y=Emissions)) +
    geom_point() +
    geom_line() +
    labs(title = "PM2.5 Emission from Motor Vehicle sources in Baltimore City") +
    ylab("Total Emission [ton]")

#dev.copy(png,"plot5.png", width=480, height=480)
#dev.off()

Answer 5

emissions from motor vehicle seems to decrease

Question 6

Q6 Compare emissions from motor vehicle sources in Baltimore City with emissions from motor vehicle sources in Los Angeles County, California (fips == "06037"). [Q] Which city has seen greater changes over time in motor vehicle emissions?

dat <- subset(NEI, (fips == "24510" | fips == "06037") & SCC %in% roadVeh$SCC)
dat <- aggregate(dat$Emissions,
                 by = list(year = dat$year, county = dat$fips),
                 FUN = sum)
names(dat)[3] <- "Emissions"

## compute changes relative to year 1999
baltimore1999 <- dat$Emissions[dat$year == 1999 & dat$county == '24510']
LA1999 <- dat$Emissions[dat$year == 1999 & dat$county == '06037']
dat$Emissions[dat$county == '24510'] <- dat$Emissions[dat$county == '24510'] - baltimore1999
dat$Emissions[dat$county == '06037'] <- dat$Emissions[dat$county == '06037'] - LA1999
baltimoreChange <- dat$Emissions[dat$year == 2008 & dat$county == "24510"]
LAChange <- dat$Emissions[dat$year == 2008 & dat$county == "06037"]

#plot
require(ggplot2)
ggplot(data = dat, aes(x=year, y=Emissions, group = county, color=county)) +
    geom_point() +
    geom_line() +
    labs(title = "Changes in PM2.5 Emission from Motor Vehicle sources \n compared to year 1999",
         subtitle = 
            paste("change in Emission in Baltimore is",round(baltimoreChange,1)
                  ,"while L.A. is", round(LAChange,1)
            )
         ) +
    ylab("Changes in Total Emission [ton]") +
    scale_color_discrete(labels=c('Los Angeles', 'Baltimore City'))

#dev.copy(png,"plot6.png", width=480, height=480)
#dev.off()

Answer 6

Baltimore city see decreases of 258.5 ton of PM2.5 Emission while Los Angeles see increases in 170.2 tons.

this was my first time working with R markdownfile. I hope to see myself improve in future work, if any.