The hang-up is what I call the message board equivalent of the zen of lazy evaluation
. A reproducible example, called a reprex sets the table for diagnosis and suggestions much better than a sort-of meta-description.
You're almost there. It should look like
suppressPackageStartupMessages(library(dplyr))
suppressPackageStartupMessages(library(stringr))
df_macro <- data.frame(
us_gdp = runif(12),
uk_gdp = c(NA,runif(11)),
jp_gdp = c(NA,NA,runif(10)),
us_inf = runif(12),
uk_inf = c(NA,NA,NA,runif(9)),
jp_inf = c(NA,runif(11)),
us_monetary_policy = runif(12),
uk_monetary_policy = runif(12),
jp_monetary_policy = runif(12),
row.names = c("Jan-78","Feb-78","Mar-78", "Apr-78", "May-78", "June-78", "July-78", "Aug-78", "Sep-78",
"Oct-78","Nov-78", "Dec-78"))
df_asset <- data.frame(
us_equity = runif(12),
uk_equity = runif(12),
jp_equity = runif(12),
us_bond = runif(12),
uk_bond = runif(12),
jp_bond = runif(12),
row.names = c("Jan-78","Feb-78","Mar-78", "Apr-78", "May-78", "June-78", "July-78", "Aug-78", "Sep-78",
"Oct-78","Nov-78", "Dec-78")
)
equity_data <- df_asset[,stringr::str_detect(names(df_asset), 'equity')]
gdp_data <- df_macro[,stringr::str_detect(names(df_asset), 'gdp')]
gdp_data
#> data frame with 0 columns and 12 rows
Created on 2020-01-17 by the reprex package (v0.3.0)
What this shows is that stringi::detect()
was the wrong tool.
So, back to you. After reviewing help(stringi)
, what is a better function/argument combination to produce a populated tibble?