This RScript is covering segments f-h in Assignment.3

#Activate required libraries
library(readr)
library(knitr)
  1. Import the dataset in RStudio. Change the name of the data frame from Federal_Stimulus_Data to fed_stimulus
#Import data to Rstudio
fed_stimulus<-read_csv('~/Desktop/MSBA/Foundation of R/Data/Use_of_ARRA_Stimulus_Funds.csv')
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   .default = col_character(),
##   `Stimulus Tracker ID` = col_double(),
##   `Stimulus Funding` = col_double(),
##   `Displaced City Funding` = col_double(),
##   `All Other Funding` = col_double(),
##   `% of Funds Spent` = col_double(),
##   `% of Funds to be Spent by Interim Spending Deadine` = col_double(),
##   `Contract Value` = col_double(),
##   `Payment Id` = col_double(),
##   `Payment Value` = col_double()
## )
## ℹ Use `spec()` for the full column specifications.
print(fed_stimulus)
## # A tibble: 13,553 x 37
##    `Project Name`     `Project Description`  `Stimulus Tracke… `Funding Categor…
##    <chr>              <chr>                              <dbl> <chr>            
##  1 Rehabilitation of… Funds will be used to…            105002 Infrastructure   
##  2 ARRA Administrati… Allocation for ARRA A…            301014 Economic and Wor…
##  3 East Houston Stre… Modify curbs and medi…            103016 Infrastructure   
##  4 Teacher Center     Preserves school-base…            501006 Education        
##  5 True Colors Resid… Finance the construct…            704007 Neighborhood Sta…
##  6 132nd Street / Li… Extend 132nd Street t…            103023 Infrastructure   
##  7 Whitman-Ingersoll… Apartment Upgrades                109001 Infrastructure   
##  8 Woodside Houses -… Roofing & Brick                   109006 Infrastructure   
##  9 Installation of S… Steel Bar Fencing.                109027 Infrastructure   
## 10 Cogeneration (Cle… The funding covers se…            201001 Energy Efficiency
## # … with 13,543 more rows, and 33 more variables: Funding Source <chr>,
## #   Stimulus Funding <dbl>, Displaced City Funding <dbl>,
## #   All Other Funding <dbl>, Award Lead City Agency <chr>,
## #   Project Lead City Agency <chr>, Project Status <chr>,
## #   % of Funds Spent <dbl>, Date Funds Awarded by Fed/State <chr>,
## #   Date Funds Announced by NYC <chr>, Estimated Start Date <chr>,
## #   Actual Start Date <chr>, Actual Completion Date <chr>,
## #   Interim Spending Deadline <chr>,
## #   % of Funds to be Spent by Interim Spending Deadine <dbl>,
## #   Final Spending Deadline <chr>, Contract Name <chr>, Contract Method <chr>,
## #   Contract Status <chr>, Contract ID # <chr>, Vendor Name <chr>,
## #   Contract Start Date <chr>, Contract End Date <chr>,
## #   New or Existing Contract <chr>, Revised Contract Start Date <chr>,
## #   Revised Contract End Date <chr>, Contract Value <dbl>,
## #   Payment Recipient <chr>, Payment Type <chr>, Payment Date <chr>,
## #   Payment Description <chr>, Payment Id <dbl>, Payment Value <dbl>
  1. Compute the sum and mean for the payment value column
#Total payment

total_payment<-format(sum(fed_stimulus$`Payment Value` ,na.rm  =TRUE),big.mark = ",")
print(total_payment)
## [1] "3,180,464,994"
#Avg payment

avg_payment<-format(mean(fed_stimulus$`Payment Value`, na.rm  =TRUE),big.mark = ",")
print(avg_payment)
## [1] "242,044.5"
  1. Create a subset of your data that returns those projects with project status is equal to the completed 50% or more. Do not include fully completed projects.
#Project with more than 50% progress except fully completed

fed_stimulus_progress<-subset.data.frame(fed_stimulus,fed_stimulus$`Project Status`=="Completed 50% or more" & fed_stimulus$`Project Status`!=" 
Fully Completed")

print(fed_stimulus_progress)
## # A tibble: 4,908 x 37
##    `Project Name`       `Project Description` `Stimulus Track… `Funding Categor…
##    <chr>                <chr>                            <dbl> <chr>            
##  1 830 Amsterdam House… Rooftop water tank              109062 Infrastructure   
##  2 CUNY pilot program … Partnership with CUN…           301006 Economic and Wor…
##  3 CUNY pilot program … Partnership with CUN…           301006 Economic and Wor…
##  4 Whitman-Ingersoll H… Apartment Upgrades              109012 Infrastructure   
##  5 Highbridge Gardens … Brick & Roof.                   109036 Infrastructure   
##  6 CUNY pilot program … Partnership with CUN…           301006 Economic and Wor…
##  7 Livonia Terrace      Finance the construc…           704003 Neighborhood Sta…
##  8 Interior Compactors… Interior Compactors             109071 Infrastructure   
##  9 FDNY Emergency Medi… An intensive 12 week…           301009 Economic and Wor…
## 10 Adoption Assistance… Provide additional f…           406001 Health and Socia…
## # … with 4,898 more rows, and 33 more variables: Funding Source <chr>,
## #   Stimulus Funding <dbl>, Displaced City Funding <dbl>,
## #   All Other Funding <dbl>, Award Lead City Agency <chr>,
## #   Project Lead City Agency <chr>, Project Status <chr>,
## #   % of Funds Spent <dbl>, Date Funds Awarded by Fed/State <chr>,
## #   Date Funds Announced by NYC <chr>, Estimated Start Date <chr>,
## #   Actual Start Date <chr>, Actual Completion Date <chr>,
## #   Interim Spending Deadline <chr>,
## #   % of Funds to be Spent by Interim Spending Deadine <dbl>,
## #   Final Spending Deadline <chr>, Contract Name <chr>, Contract Method <chr>,
## #   Contract Status <chr>, Contract ID # <chr>, Vendor Name <chr>,
## #   Contract Start Date <chr>, Contract End Date <chr>,
## #   New or Existing Contract <chr>, Revised Contract Start Date <chr>,
## #   Revised Contract End Date <chr>, Contract Value <dbl>,
## #   Payment Recipient <chr>, Payment Type <chr>, Payment Date <chr>,
## #   Payment Description <chr>, Payment Id <dbl>, Payment Value <dbl>