Question #1

library(jsonlite) #load json files
library(tidyverse)
## Loading tidyverse: ggplot2
## Loading tidyverse: tibble
## Loading tidyverse: tidyr
## Loading tidyverse: readr
## Loading tidyverse: purrr
## Loading tidyverse: dplyr
## Conflicts with tidy packages ----------------------------------------------
## filter(): dplyr, stats
## lag():    dplyr, stats
library(magrittr)
## 
## Attaching package: 'magrittr'
## The following object is masked from 'package:purrr':
## 
##     set_names
## The following object is masked from 'package:tidyr':
## 
##     extract
bwide <-readRDS("bomber_wide.rds")
bwide <- as_tibble(bwide)
bwide %>% 
  gather(Year, FH, -Type, -MD)
## # A tibble: 57 × 4
##      Type    MD  Year    FH
##     <chr> <chr> <chr> <int>
## 1  Bomber   B-1  1996 26914
## 2  Bomber   B-2  1996  2364
## 3  Bomber  B-52  1996 28511
## 4  Bomber   B-1  1997 25219
## 5  Bomber   B-2  1997  2776
## 6  Bomber  B-52  1997 26034
## 7  Bomber   B-1  1998 24205
## 8  Bomber   B-2  1998  2166
## 9  Bomber  B-52  1998 25639
## 10 Bomber   B-1  1999 23306
## # ... with 47 more rows

Question #2

blong <- readRDS("bomber_long.rds")
blong <- as_tibble(blong)

blong %>%
spread(key=Output, value=Value)
## # A tibble: 57 × 6
##      Type    MD    FY      Cost    FH   Gallons
## *   <chr> <chr> <int>     <int> <int>     <int>
## 1  Bomber   B-1  1996  72753781 26914  88594449
## 2  Bomber   B-1  1997  71297263 25219  85484074
## 3  Bomber   B-1  1998  84026805 24205  85259038
## 4  Bomber   B-1  1999  71848336 23306  79323816
## 5  Bomber   B-1  2000  58439777 25013  86230284
## 6  Bomber   B-1  2001  94946077 25059  86892432
## 7  Bomber   B-1  2002  96458536 26581  89198262
## 8  Bomber   B-1  2003  68650070 21491  74485788
## 9  Bomber   B-1  2004 101895634 28118 101397707
## 10 Bomber   B-1  2005 124816690 21859  78410415
## # ... with 47 more rows

Question #3

bomcom <- readRDS("bomber_combined.rds")
bomcom <- as_tibble(bomcom)

bomcom %>%
  separate(AC, into = c("Type", "MD"), sep = "\\s+")
## # A tibble: 57 × 6
##      Type    MD    FY      Cost    FH   Gallons
## *   <chr> <chr> <int>     <int> <int>     <int>
## 1  Bomber   B-1  1996  72753781 26914  88594449
## 2  Bomber   B-1  1997  71297263 25219  85484074
## 3  Bomber   B-1  1998  84026805 24205  85259038
## 4  Bomber   B-1  1999  71848336 23306  79323816
## 5  Bomber   B-1  2000  58439777 25013  86230284
## 6  Bomber   B-1  2001  94946077 25059  86892432
## 7  Bomber   B-1  2002  96458536 26581  89198262
## 8  Bomber   B-1  2003  68650070 21491  74485788
## 9  Bomber   B-1  2004 101895634 28118 101397707
## 10 Bomber   B-1  2005 124816690 21859  78410415
## # ... with 47 more rows

Question # 4

Could not get this file to load in rmarkdown ( others worked) but it worked in the r code

bompref <-readRDS(“bomber_prefix.rds”)
bompref <- as_tibble(bompref)

bompref %>%
unite(MD, prefix, number,sep = “-”) %>%
separate(Output, into = c(“FY”, “FH”), sep = “\s+”) %>%
spread(key=Output, value=Value)

Question #5

bommess <- readRDS(“bomber_mess.rds”) bommess <- as_tibble(bommess)

bommess %>% unite(MD, prefix, number,sep = “-”) %>% separate(Metric, into = c(“FY”, “FH”), sep = “_“) %>% spread(key=FH, value=Value)

Question #6

These data sets would not load in rmarkdown but result obtained in r

prog <- readRDS(“ws_programmatics.rds”)
prog <- as_tibble
cats <- readRDS(“ws_categorizations.rds”)
cats <- as_tibble
join <- inner_join(prog, cats) %>%
filter(FY == 2014, Base == “MINOT AFB (ND)”) %>%
filter(System %in% c(“AIRCRAFT”, “MISSILES”)) %>%
group_by(System) %>%
mutate(Total_Sum=Total_O.S+End_Strength)

Question 7

Could not import data sets in rmarkdown
joint <- inner_join(prog, cats) %>%
filter(FY == 2014) %>%
mutate(CFPH=Total_O.S / FH) %>%
group_by(Base) %>%
summarize(Mean_Base =mean(CFPH, na.rm=TRUE)) %>%
arrange(desc(Mean_Base)) %>%
top_n(10) %>%
ggplot +
geom_bar(mapping = aes(x=reorder(Base, -Mean_Base), y=Mean_Base, fill = Base),stat = “identity”) +
labs(title = “Top 10 Bases with Highest Cost/Flying Hour”) +
labs(x=“Airforce Base”, y=“Cost/Flying Hour”)

Question 8

Could not import data sets in rmarkdown
##Plot #1
scatter1 <- inner_join(prog, cats) %>%
filter(Base == “WRIGHT-PATTERSON AFB (OH)”) %>%

ggplot(scatter1, aes(End_Strength, Total_O.S )) +
geom_point() +
labs(title = “Total OS vs End Strength for Wright Patterson AFB”) +
labs(x=“End Strength”, y=“Total_O.S”)