Week 1 - In-Class Exercise

Author

Jenny Park

load the package

library(tidyverse)
── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
✔ ggplot2 3.4.0     ✔ purrr   1.0.1
✔ tibble  3.1.8     ✔ dplyr   1.1.0
✔ tidyr   1.3.0     ✔ stringr 1.5.0
✔ readr   2.1.3     ✔ forcats 1.0.0
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
library(knitr)
library(dplyr)

load the data

# assign the url to `github_raw_csv_url`
github_raw_csv_url <- "https://raw.githubusercontent.com/t-emery/sais-susfin_data/main/datasets/blackrock_etf_screener_2022-08-30.csv"

# read in the data, and assign it to the object `blackrock_etf_data`
blackrock_etf_data <- read_csv(github_raw_csv_url)
Rows: 393 Columns: 22
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (14): ticker, name, incept_date, net_assets_as_of, asset_class, sub_asse...
dbl  (8): gross_expense_ratio_percent, net_expense_ratio_percent, net_assets...

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
blackrock_etf_data
# A tibble: 393 × 22
   ticker name    incep…¹ gross…² net_e…³ net_a…⁴ net_a…⁵ asset…⁶ sub_a…⁷ region
   <chr>  <chr>   <chr>     <dbl>   <dbl>   <dbl> <chr>   <chr>   <chr>   <chr> 
 1 IVV    iShare… 5/15/00    0.03    0.03 297663. 8/30/22 Equity  Large … North…
 2 IEFA   iShare… 10/18/…    0.07    0.07  84222. 8/30/22 Equity  All Cap Global
 3 AGG    iShare… 9/22/03    0.04    0.03  82344. 8/30/22 Fixed … Multi … North…
 4 IJR    iShare… 5/22/00    0.06    0.06  66533. 8/30/22 Equity  Small … North…
 5 IEMG   iShare… 10/18/…    0.09    0.09  64920. 8/30/22 Equity  All Cap Global
 6 IWF    iShare… 5/22/00    0.18    0.18  61831. 8/30/22 Equity  Large/… North…
 7 IJH    iShare… 5/22/00    0.05    0.05  61424. 8/30/22 Equity  Mid Cap North…
 8 IWM    iShare… 5/22/00    0.19    0.19  53048. 8/30/22 Equity  Small … North…
 9 IWD    iShare… 5/22/00    0.18    0.18  51913. 8/30/22 Equity  Large/… North…
10 EFA    iShare… 8/14/01    0.32    0.32  44144. 8/30/22 Equity  Large/… Global
# … with 383 more rows, 12 more variables: market <chr>, location <chr>,
#   investment_style <chr>,
#   sustainability_characteristics_msci_esg_fund_ratings_msci_esg_fund_rating_aaa_ccc <chr>,
#   msci_esg_quality_score_0_10 <dbl>,
#   msci_weighted_average_carbon_intensity_tons_co2e_m_sales <dbl>,
#   msci_esg_percent_coverage <dbl>, sustainable_classification <chr>,
#   name_wo_ishares_etf <chr>, is_esg <chr>, years_from_inception <dbl>, …
view(blackrock_etf_data)
glimpse(blackrock_etf_data)
Rows: 393
Columns: 22
$ ticker                                                                            <chr> …
$ name                                                                              <chr> …
$ incept_date                                                                       <chr> …
$ gross_expense_ratio_percent                                                       <dbl> …
$ net_expense_ratio_percent                                                         <dbl> …
$ net_assets_usd_mn                                                                 <dbl> …
$ net_assets_as_of                                                                  <chr> …
$ asset_class                                                                       <chr> …
$ sub_asset_class                                                                   <chr> …
$ region                                                                            <chr> …
$ market                                                                            <chr> …
$ location                                                                          <chr> …
$ investment_style                                                                  <chr> …
$ sustainability_characteristics_msci_esg_fund_ratings_msci_esg_fund_rating_aaa_ccc <chr> …
$ msci_esg_quality_score_0_10                                                       <dbl> …
$ msci_weighted_average_carbon_intensity_tons_co2e_m_sales                          <dbl> …
$ msci_esg_percent_coverage                                                         <dbl> …
$ sustainable_classification                                                        <chr> …
$ name_wo_ishares_etf                                                               <chr> …
$ is_esg                                                                            <chr> …
$ years_from_inception                                                              <dbl> …
$ year_launched                                                                     <dbl> …
mini_blackrock_data <- blackrock_etf_data %>% 
  # group by whether fund is ESG or not
  group_by(is_esg) %>% 
  # top 5 from each group, by net assets
  slice_max(order_by = net_assets_usd_mn, n = 5) %>% 
  # select following columns 
  select(ticker, name, asset_class, sub_asset_class, region, incept_date, net_assets_usd_mn, msci_weighted_average_carbon_intensity_tons_co2e_m_sales) %>% 
  rename(co2_intensity = msci_weighted_average_carbon_intensity_tons_co2e_m_sales) %>%  
  ungroup()
Adding missing grouping variables: `is_esg`
mini_blackrock_data
# A tibble: 10 × 9
   is_esg       ticker name       asset…¹ sub_a…² region incep…³ net_a…⁴ co2_i…⁵
   <chr>        <chr>  <chr>      <chr>   <chr>   <chr>  <chr>     <dbl>   <dbl>
 1 ESG Fund     ESGU   iShares E… Equity  Large/… North… 12/1/16  22377.   104. 
 2 ESG Fund     ESGD   iShares E… Equity  Large/… Global 6/28/16   6426.   104. 
 3 ESG Fund     ICLN   iShares G… Equity  All Cap Global 6/24/08   5628.   266. 
 4 ESG Fund     ESGE   iShares E… Equity  Large/… Global 6/28/16   4234.   168. 
 5 ESG Fund     DSI    iShares M… Equity  Large/… North… 11/14/…   3689.    72.7
 6 Regular Fund IVV    iShares C… Equity  Large … North… 5/15/00 297663.   148. 
 7 Regular Fund IEFA   iShares C… Equity  All Cap Global 10/18/…  84222.   127. 
 8 Regular Fund AGG    iShares C… Fixed … Multi … North… 9/22/03  82344.   283. 
 9 Regular Fund IJR    iShares C… Equity  Small … North… 5/22/00  66533.   133. 
10 Regular Fund IEMG   iShares C… Equity  All Cap Global 10/18/…  64920.   369. 
# … with abbreviated variable names ¹​asset_class, ²​sub_asset_class,
#   ³​incept_date, ⁴​net_assets_usd_mn, ⁵​co2_intensity
mini_blackrock_data %>% glimpse()
Rows: 10
Columns: 9
$ is_esg            <chr> "ESG Fund", "ESG Fund", "ESG Fund", "ESG Fund", "ESG…
$ ticker            <chr> "ESGU", "ESGD", "ICLN", "ESGE", "DSI", "IVV", "IEFA"…
$ name              <chr> "iShares ESG Aware MSCI USA ETF", "iShares ESG Aware…
$ asset_class       <chr> "Equity", "Equity", "Equity", "Equity", "Equity", "E…
$ sub_asset_class   <chr> "Large/Mid Cap", "Large/Mid Cap", "All Cap", "Large/…
$ region            <chr> "North America", "Global", "Global", "Global", "Nort…
$ incept_date       <chr> "12/1/16", "6/28/16", "6/24/08", "6/28/16", "11/14/0…
$ net_assets_usd_mn <dbl> 22376.688, 6425.673, 5628.011, 4233.544, 3688.930, 2…
$ co2_intensity     <dbl> 103.60, 103.83, 265.82, 167.71, 72.73, 148.34, 126.6…

Verb 1: select()

# select three columns that has the word "asset"
mini_blackrock_data %>%
  select(contains("asset"))
# A tibble: 10 × 3
   asset_class  sub_asset_class net_assets_usd_mn
   <chr>        <chr>                       <dbl>
 1 Equity       Large/Mid Cap              22377.
 2 Equity       Large/Mid Cap               6426.
 3 Equity       All Cap                     5628.
 4 Equity       Large/Mid Cap               4234.
 5 Equity       Large/Mid Cap               3689.
 6 Equity       Large Cap                 297663.
 7 Equity       All Cap                    84222.
 8 Fixed Income Multi Sectors              82344.
 9 Equity       Small Cap                  66533.
10 Equity       All Cap                    64920.
# name of the fund
mini_blackrock_data %>%
  select("name")
# A tibble: 10 × 1
   name                                  
   <chr>                                 
 1 iShares ESG Aware MSCI USA ETF        
 2 iShares ESG Aware MSCI EAFE ETF       
 3 iShares Global Clean Energy ETF       
 4 iShares ESG Aware MSCI EM ETF         
 5 iShares MSCI KLD 400 Social ETF       
 6 iShares Core S&P 500 ETF              
 7 iShares Core MSCI EAFE ETF            
 8 iShares Core U.S. Aggregate Bond ETF  
 9 iShares Core S&P Small-Cap ETF        
10 iShares Core MSCI Emerging Markets ETF
# whether fund is ESG or not
mini_blackrock_data %>%
  select("is_esg")
# A tibble: 10 × 1
   is_esg      
   <chr>       
 1 ESG Fund    
 2 ESG Fund    
 3 ESG Fund    
 4 ESG Fund    
 5 ESG Fund    
 6 Regular Fund
 7 Regular Fund
 8 Regular Fund
 9 Regular Fund
10 Regular Fund
# asset class 
mini_blackrock_data %>%
  select("asset_class")
# A tibble: 10 × 1
   asset_class 
   <chr>       
 1 Equity      
 2 Equity      
 3 Equity      
 4 Equity      
 5 Equity      
 6 Equity      
 7 Equity      
 8 Fixed Income
 9 Equity      
10 Equity      

Verb 2: filter()

mini_blackrock_data %>%
  filter(is_esg == "ESG Fund")
# A tibble: 5 × 9
  is_esg   ticker name            asset…¹ sub_a…² region incep…³ net_a…⁴ co2_i…⁵
  <chr>    <chr>  <chr>           <chr>   <chr>   <chr>  <chr>     <dbl>   <dbl>
1 ESG Fund ESGU   iShares ESG Aw… Equity  Large/… North… 12/1/16  22377.   104. 
2 ESG Fund ESGD   iShares ESG Aw… Equity  Large/… Global 6/28/16   6426.   104. 
3 ESG Fund ICLN   iShares Global… Equity  All Cap Global 6/24/08   5628.   266. 
4 ESG Fund ESGE   iShares ESG Aw… Equity  Large/… Global 6/28/16   4234.   168. 
5 ESG Fund DSI    iShares MSCI K… Equity  Large/… North… 11/14/…   3689.    72.7
# … with abbreviated variable names ¹​asset_class, ²​sub_asset_class,
#   ³​incept_date, ⁴​net_assets_usd_mn, ⁵​co2_intensity
mini_blackrock_data %>%
  filter(is_esg == "ESG Fund")
# A tibble: 5 × 9
  is_esg   ticker name            asset…¹ sub_a…² region incep…³ net_a…⁴ co2_i…⁵
  <chr>    <chr>  <chr>           <chr>   <chr>   <chr>  <chr>     <dbl>   <dbl>
1 ESG Fund ESGU   iShares ESG Aw… Equity  Large/… North… 12/1/16  22377.   104. 
2 ESG Fund ESGD   iShares ESG Aw… Equity  Large/… Global 6/28/16   6426.   104. 
3 ESG Fund ICLN   iShares Global… Equity  All Cap Global 6/24/08   5628.   266. 
4 ESG Fund ESGE   iShares ESG Aw… Equity  Large/… Global 6/28/16   4234.   168. 
5 ESG Fund DSI    iShares MSCI K… Equity  Large/… North… 11/14/…   3689.    72.7
# … with abbreviated variable names ¹​asset_class, ²​sub_asset_class,
#   ³​incept_date, ⁴​net_assets_usd_mn, ⁵​co2_intensity
mini_blackrock_data %>%
  filter(net_assets_usd_mn > 10000)
# A tibble: 6 × 9
  is_esg       ticker name        asset…¹ sub_a…² region incep…³ net_a…⁴ co2_i…⁵
  <chr>        <chr>  <chr>       <chr>   <chr>   <chr>  <chr>     <dbl>   <dbl>
1 ESG Fund     ESGU   iShares ES… Equity  Large/… North… 12/1/16  22377.    104.
2 Regular Fund IVV    iShares Co… Equity  Large … North… 5/15/00 297663.    148.
3 Regular Fund IEFA   iShares Co… Equity  All Cap Global 10/18/…  84222.    127.
4 Regular Fund AGG    iShares Co… Fixed … Multi … North… 9/22/03  82344.    283.
5 Regular Fund IJR    iShares Co… Equity  Small … North… 5/22/00  66533.    133.
6 Regular Fund IEMG   iShares Co… Equity  All Cap Global 10/18/…  64920.    369.
# … with abbreviated variable names ¹​asset_class, ²​sub_asset_class,
#   ³​incept_date, ⁴​net_assets_usd_mn, ⁵​co2_intensity
mini_blackrock_data %>%
  filter(net_assets_usd_mn < 10000)
# A tibble: 4 × 9
  is_esg   ticker name            asset…¹ sub_a…² region incep…³ net_a…⁴ co2_i…⁵
  <chr>    <chr>  <chr>           <chr>   <chr>   <chr>  <chr>     <dbl>   <dbl>
1 ESG Fund ESGD   iShares ESG Aw… Equity  Large/… Global 6/28/16   6426.   104. 
2 ESG Fund ICLN   iShares Global… Equity  All Cap Global 6/24/08   5628.   266. 
3 ESG Fund ESGE   iShares ESG Aw… Equity  Large/… Global 6/28/16   4234.   168. 
4 ESG Fund DSI    iShares MSCI K… Equity  Large/… North… 11/14/…   3689.    72.7
# … with abbreviated variable names ¹​asset_class, ²​sub_asset_class,
#   ³​incept_date, ⁴​net_assets_usd_mn, ⁵​co2_intensity
mini_blackrock_data %>%
  filter(co2_intensity >= 100)
# A tibble: 9 × 9
  is_esg       ticker name        asset…¹ sub_a…² region incep…³ net_a…⁴ co2_i…⁵
  <chr>        <chr>  <chr>       <chr>   <chr>   <chr>  <chr>     <dbl>   <dbl>
1 ESG Fund     ESGU   iShares ES… Equity  Large/… North… 12/1/16  22377.    104.
2 ESG Fund     ESGD   iShares ES… Equity  Large/… Global 6/28/16   6426.    104.
3 ESG Fund     ICLN   iShares Gl… Equity  All Cap Global 6/24/08   5628.    266.
4 ESG Fund     ESGE   iShares ES… Equity  Large/… Global 6/28/16   4234.    168.
5 Regular Fund IVV    iShares Co… Equity  Large … North… 5/15/00 297663.    148.
6 Regular Fund IEFA   iShares Co… Equity  All Cap Global 10/18/…  84222.    127.
7 Regular Fund AGG    iShares Co… Fixed … Multi … North… 9/22/03  82344.    283.
8 Regular Fund IJR    iShares Co… Equity  Small … North… 5/22/00  66533.    133.
9 Regular Fund IEMG   iShares Co… Equity  All Cap Global 10/18/…  64920.    369.
# … with abbreviated variable names ¹​asset_class, ²​sub_asset_class,
#   ³​incept_date, ⁴​net_assets_usd_mn, ⁵​co2_intensity
mini_blackrock_data %>%
  filter(co2_intensity <= 100)
# A tibble: 1 × 9
  is_esg   ticker name            asset…¹ sub_a…² region incep…³ net_a…⁴ co2_i…⁵
  <chr>    <chr>  <chr>           <chr>   <chr>   <chr>  <chr>     <dbl>   <dbl>
1 ESG Fund DSI    iShares MSCI K… Equity  Large/… North… 11/14/…   3689.    72.7
# … with abbreviated variable names ¹​asset_class, ²​sub_asset_class,
#   ³​incept_date, ⁴​net_assets_usd_mn, ⁵​co2_intensity
mini_blackrock_data %>%
  filter(ticker %in% c("ESGU", "IVV", "DSI"))
# A tibble: 3 × 9
  is_esg       ticker name        asset…¹ sub_a…² region incep…³ net_a…⁴ co2_i…⁵
  <chr>        <chr>  <chr>       <chr>   <chr>   <chr>  <chr>     <dbl>   <dbl>
1 ESG Fund     ESGU   iShares ES… Equity  Large/… North… 12/1/16  22377.   104. 
2 ESG Fund     DSI    iShares MS… Equity  Large/… North… 11/14/…   3689.    72.7
3 Regular Fund IVV    iShares Co… Equity  Large … North… 5/15/00 297663.   148. 
# … with abbreviated variable names ¹​asset_class, ²​sub_asset_class,
#   ³​incept_date, ⁴​net_assets_usd_mn, ⁵​co2_intensity
tickers_1 <- c("ESGU", "IVV", "DSI")

mini_blackrock_data %>%
  filter(ticker %in% tickers_1)
# A tibble: 3 × 9
  is_esg       ticker name        asset…¹ sub_a…² region incep…³ net_a…⁴ co2_i…⁵
  <chr>        <chr>  <chr>       <chr>   <chr>   <chr>  <chr>     <dbl>   <dbl>
1 ESG Fund     ESGU   iShares ES… Equity  Large/… North… 12/1/16  22377.   104. 
2 ESG Fund     DSI    iShares MS… Equity  Large/… North… 11/14/…   3689.    72.7
3 Regular Fund IVV    iShares Co… Equity  Large … North… 5/15/00 297663.   148. 
# … with abbreviated variable names ¹​asset_class, ²​sub_asset_class,
#   ³​incept_date, ⁴​net_assets_usd_mn, ⁵​co2_intensity
mini_blackrock_data %>%
  filter(is_esg == "ESG Fund")
# A tibble: 5 × 9
  is_esg   ticker name            asset…¹ sub_a…² region incep…³ net_a…⁴ co2_i…⁵
  <chr>    <chr>  <chr>           <chr>   <chr>   <chr>  <chr>     <dbl>   <dbl>
1 ESG Fund ESGU   iShares ESG Aw… Equity  Large/… North… 12/1/16  22377.   104. 
2 ESG Fund ESGD   iShares ESG Aw… Equity  Large/… Global 6/28/16   6426.   104. 
3 ESG Fund ICLN   iShares Global… Equity  All Cap Global 6/24/08   5628.   266. 
4 ESG Fund ESGE   iShares ESG Aw… Equity  Large/… Global 6/28/16   4234.   168. 
5 ESG Fund DSI    iShares MSCI K… Equity  Large/… North… 11/14/…   3689.    72.7
# … with abbreviated variable names ¹​asset_class, ²​sub_asset_class,
#   ³​incept_date, ⁴​net_assets_usd_mn, ⁵​co2_intensity
mini_blackrock_data %>%
  filter(asset_class == "Fixed Income")
# A tibble: 1 × 9
  is_esg       ticker name        asset…¹ sub_a…² region incep…³ net_a…⁴ co2_i…⁵
  <chr>        <chr>  <chr>       <chr>   <chr>   <chr>  <chr>     <dbl>   <dbl>
1 Regular Fund AGG    iShares Co… Fixed … Multi … North… 9/22/03  82344.    283.
# … with abbreviated variable names ¹​asset_class, ²​sub_asset_class,
#   ³​incept_date, ⁴​net_assets_usd_mn, ⁵​co2_intensity

verb 3: mutate()

mini_blackrock_data %>%
  select(name, is_esg, incept_date) %>%
  mutate(incept_date= lubridate::mdy(incept_date),
         incept_year = lubridate::year(incept_date),
         years_since_incept = lubridate::interval(incept_date, Sys.Date())/lubridate::years(1))
# A tibble: 10 × 5
   name                                   is_esg      incept_d…¹ incep…² years…³
   <chr>                                  <chr>       <date>       <dbl>   <dbl>
 1 iShares ESG Aware MSCI USA ETF         ESG Fund    2016-12-01    2016    6.22
 2 iShares ESG Aware MSCI EAFE ETF        ESG Fund    2016-06-28    2016    6.65
 3 iShares Global Clean Energy ETF        ESG Fund    2008-06-24    2008   14.7 
 4 iShares ESG Aware MSCI EM ETF          ESG Fund    2016-06-28    2016    6.65
 5 iShares MSCI KLD 400 Social ETF        ESG Fund    2006-11-14    2006   16.3 
 6 iShares Core S&P 500 ETF               Regular Fu… 2000-05-15    2000   22.8 
 7 iShares Core MSCI EAFE ETF             Regular Fu… 2012-10-18    2012   10.3 
 8 iShares Core U.S. Aggregate Bond ETF   Regular Fu… 2003-09-22    2003   19.4 
 9 iShares Core S&P Small-Cap ETF         Regular Fu… 2000-05-22    2000   22.7 
10 iShares Core MSCI Emerging Markets ETF Regular Fu… 2012-10-18    2012   10.3 
# … with abbreviated variable names ¹​incept_date, ²​incept_year,
#   ³​years_since_incept
mini_blackrock_data %>%
  mutate(net_assets_usd_bn = net_assets_usd_mn / 1000)
# A tibble: 10 × 10
   is_esg    ticker name  asset…¹ sub_a…² region incep…³ net_a…⁴ co2_i…⁵ net_a…⁶
   <chr>     <chr>  <chr> <chr>   <chr>   <chr>  <chr>     <dbl>   <dbl>   <dbl>
 1 ESG Fund  ESGU   iSha… Equity  Large/… North… 12/1/16  22377.   104.    22.4 
 2 ESG Fund  ESGD   iSha… Equity  Large/… Global 6/28/16   6426.   104.     6.43
 3 ESG Fund  ICLN   iSha… Equity  All Cap Global 6/24/08   5628.   266.     5.63
 4 ESG Fund  ESGE   iSha… Equity  Large/… Global 6/28/16   4234.   168.     4.23
 5 ESG Fund  DSI    iSha… Equity  Large/… North… 11/14/…   3689.    72.7    3.69
 6 Regular … IVV    iSha… Equity  Large … North… 5/15/00 297663.   148.   298.  
 7 Regular … IEFA   iSha… Equity  All Cap Global 10/18/…  84222.   127.    84.2 
 8 Regular … AGG    iSha… Fixed … Multi … North… 9/22/03  82344.   283.    82.3 
 9 Regular … IJR    iSha… Equity  Small … North… 5/22/00  66533.   133.    66.5 
10 Regular … IEMG   iSha… Equity  All Cap Global 10/18/…  64920.   369.    64.9 
# … with abbreviated variable names ¹​asset_class, ²​sub_asset_class,
#   ³​incept_date, ⁴​net_assets_usd_mn, ⁵​co2_intensity, ⁶​net_assets_usd_bn

Verb 4: arrange()

mini_blackrock_data %>%
  arrange(co2_intensity)
# A tibble: 10 × 9
   is_esg       ticker name       asset…¹ sub_a…² region incep…³ net_a…⁴ co2_i…⁵
   <chr>        <chr>  <chr>      <chr>   <chr>   <chr>  <chr>     <dbl>   <dbl>
 1 ESG Fund     DSI    iShares M… Equity  Large/… North… 11/14/…   3689.    72.7
 2 ESG Fund     ESGU   iShares E… Equity  Large/… North… 12/1/16  22377.   104. 
 3 ESG Fund     ESGD   iShares E… Equity  Large/… Global 6/28/16   6426.   104. 
 4 Regular Fund IEFA   iShares C… Equity  All Cap Global 10/18/…  84222.   127. 
 5 Regular Fund IJR    iShares C… Equity  Small … North… 5/22/00  66533.   133. 
 6 Regular Fund IVV    iShares C… Equity  Large … North… 5/15/00 297663.   148. 
 7 ESG Fund     ESGE   iShares E… Equity  Large/… Global 6/28/16   4234.   168. 
 8 ESG Fund     ICLN   iShares G… Equity  All Cap Global 6/24/08   5628.   266. 
 9 Regular Fund AGG    iShares C… Fixed … Multi … North… 9/22/03  82344.   283. 
10 Regular Fund IEMG   iShares C… Equity  All Cap Global 10/18/…  64920.   369. 
# … with abbreviated variable names ¹​asset_class, ²​sub_asset_class,
#   ³​incept_date, ⁴​net_assets_usd_mn, ⁵​co2_intensity
mini_blackrock_data %>%
  arrange(co2_intensity %>%
            desc())
# A tibble: 10 × 9
   is_esg       ticker name       asset…¹ sub_a…² region incep…³ net_a…⁴ co2_i…⁵
   <chr>        <chr>  <chr>      <chr>   <chr>   <chr>  <chr>     <dbl>   <dbl>
 1 Regular Fund IEMG   iShares C… Equity  All Cap Global 10/18/…  64920.   369. 
 2 Regular Fund AGG    iShares C… Fixed … Multi … North… 9/22/03  82344.   283. 
 3 ESG Fund     ICLN   iShares G… Equity  All Cap Global 6/24/08   5628.   266. 
 4 ESG Fund     ESGE   iShares E… Equity  Large/… Global 6/28/16   4234.   168. 
 5 Regular Fund IVV    iShares C… Equity  Large … North… 5/15/00 297663.   148. 
 6 Regular Fund IJR    iShares C… Equity  Small … North… 5/22/00  66533.   133. 
 7 Regular Fund IEFA   iShares C… Equity  All Cap Global 10/18/…  84222.   127. 
 8 ESG Fund     ESGD   iShares E… Equity  Large/… Global 6/28/16   6426.   104. 
 9 ESG Fund     ESGU   iShares E… Equity  Large/… North… 12/1/16  22377.   104. 
10 ESG Fund     DSI    iShares M… Equity  Large/… North… 11/14/…   3689.    72.7
# … with abbreviated variable names ¹​asset_class, ²​sub_asset_class,
#   ³​incept_date, ⁴​net_assets_usd_mn, ⁵​co2_intensity
mini_blackrock_data %>%
  arrange(is_esg, co2_intensity %>%
            desc())
# A tibble: 10 × 9
   is_esg       ticker name       asset…¹ sub_a…² region incep…³ net_a…⁴ co2_i…⁵
   <chr>        <chr>  <chr>      <chr>   <chr>   <chr>  <chr>     <dbl>   <dbl>
 1 ESG Fund     ICLN   iShares G… Equity  All Cap Global 6/24/08   5628.   266. 
 2 ESG Fund     ESGE   iShares E… Equity  Large/… Global 6/28/16   4234.   168. 
 3 ESG Fund     ESGD   iShares E… Equity  Large/… Global 6/28/16   6426.   104. 
 4 ESG Fund     ESGU   iShares E… Equity  Large/… North… 12/1/16  22377.   104. 
 5 ESG Fund     DSI    iShares M… Equity  Large/… North… 11/14/…   3689.    72.7
 6 Regular Fund IEMG   iShares C… Equity  All Cap Global 10/18/…  64920.   369. 
 7 Regular Fund AGG    iShares C… Fixed … Multi … North… 9/22/03  82344.   283. 
 8 Regular Fund IVV    iShares C… Equity  Large … North… 5/15/00 297663.   148. 
 9 Regular Fund IJR    iShares C… Equity  Small … North… 5/22/00  66533.   133. 
10 Regular Fund IEFA   iShares C… Equity  All Cap Global 10/18/…  84222.   127. 
# … with abbreviated variable names ¹​asset_class, ²​sub_asset_class,
#   ³​incept_date, ⁴​net_assets_usd_mn, ⁵​co2_intensity
mini_blackrock_data %>%
  arrange(asset_class, net_assets_usd_mn %>%
            desc())
# A tibble: 10 × 9
   is_esg       ticker name       asset…¹ sub_a…² region incep…³ net_a…⁴ co2_i…⁵
   <chr>        <chr>  <chr>      <chr>   <chr>   <chr>  <chr>     <dbl>   <dbl>
 1 Regular Fund IVV    iShares C… Equity  Large … North… 5/15/00 297663.   148. 
 2 Regular Fund IEFA   iShares C… Equity  All Cap Global 10/18/…  84222.   127. 
 3 Regular Fund IJR    iShares C… Equity  Small … North… 5/22/00  66533.   133. 
 4 Regular Fund IEMG   iShares C… Equity  All Cap Global 10/18/…  64920.   369. 
 5 ESG Fund     ESGU   iShares E… Equity  Large/… North… 12/1/16  22377.   104. 
 6 ESG Fund     ESGD   iShares E… Equity  Large/… Global 6/28/16   6426.   104. 
 7 ESG Fund     ICLN   iShares G… Equity  All Cap Global 6/24/08   5628.   266. 
 8 ESG Fund     ESGE   iShares E… Equity  Large/… Global 6/28/16   4234.   168. 
 9 ESG Fund     DSI    iShares M… Equity  Large/… North… 11/14/…   3689.    72.7
10 Regular Fund AGG    iShares C… Fixed … Multi … North… 9/22/03  82344.   283. 
# … with abbreviated variable names ¹​asset_class, ²​sub_asset_class,
#   ³​incept_date, ⁴​net_assets_usd_mn, ⁵​co2_intensity

Verb 5: summarize()

mini_blackrock_data %>%
  summarize(sum_assets_mn = sum(net_assets_usd_mn), 
            avg_assets_mn = mean(net_assets_usd_mn))
# A tibble: 1 × 2
  sum_assets_mn avg_assets_mn
          <dbl>         <dbl>
1       638036.        63804.
mini_blackrock_data %>%
  summarize(median_carbon_intensity = 
              median(co2_intensity))
# A tibble: 1 × 1
  median_carbon_intensity
                    <dbl>
1                    141.

Verb 6: group_by ()

mini_blackrock_data %>%
  group_by(is_esg) %>% 
  summarize(sum_assets_mn = sum(net_assets_usd_mn),
            avg_assets_mn = mean(net_assets_usd_mn))
# A tibble: 2 × 3
  is_esg       sum_assets_mn avg_assets_mn
  <chr>                <dbl>         <dbl>
1 ESG Fund            42353.         8471.
2 Regular Fund       595683.       119137.
mini_blackrock_data %>%
  group_by(asset_class) %>% 
  summarize(sum_carbon_intensity = 
              sum(co2_intensity),
            avg_carbon_intensity =
              mean(co2_intensity))
# A tibble: 2 × 3
  asset_class  sum_carbon_intensity avg_carbon_intensity
  <chr>                       <dbl>                <dbl>
1 Equity                      1490.                 166.
2 Fixed Income                 283.                 283.
mini_blackrock_data %>%
  group_by(sub_asset_class) %>% 
  summarize(sum_carbon_intensity = 
              sum(co2_intensity),
            avg_carbon_intensity =
              mean(co2_intensity))
# A tibble: 5 × 3
  sub_asset_class sum_carbon_intensity avg_carbon_intensity
  <chr>                          <dbl>                <dbl>
1 All Cap                         761.                 254.
2 Large Cap                       148.                 148.
3 Large/Mid Cap                   448.                 112.
4 Multi Sectors                   283.                 283.
5 Small Cap                       133.                 133.
ggplot(mini_blackrock_data, aes(x = net_assets_usd_mn, y = co2_intensity, color = is_esg)) +
  geom_point()

ggplot(data = mini_blackrock_data) +
  geom_point(mapping = aes(x = net_assets_usd_mn, y = co2_intensity)) + facet_wrap(~ is_esg, nrow = 2)

ggplot(data = mini_blackrock_data, mapping = aes(x = net_assets_usd_mn, y = co2_intensity)) + 
  geom_point(mapping = aes(color = is_esg)) +
  geom_smooth()
`geom_smooth()` using method = 'loess' and formula = 'y ~ x'

ggplot(mini_blackrock_data, aes(x = sub_asset_class, y = net_assets_usd_mn)) +
  geom_col()

ggplot(data = mini_blackrock_data) +
  stat_summary(
    mapping = aes(x = sub_asset_class, y = net_assets_usd_mn), 
    fun.min =  min,
    fun.max = max,
    fun = median
  )