Goal
I am trying to make a data frame that will match the files needed to populate certain variables. I hope to pass this object further down the workflow to control a wrangling function.
I take the object X100samples and put the variable names into a dataframe. I am hoping that from there I can mutate, and conditionally check the names in the dataframe for regular expression such as "source". If the expression is found then I will populate those elements in the new column with a particular file name.
Simplified Reprex
library(dplyr)
library(tibble)
library(stringr)
stead_data <-tibble(c(
"network_code","receiver_code",
"receiver_type",
"receiver_latitude",
"receiver_longitude",
"receiver_elevation_m",
"p_arrival_sample",
"p_status","p_weight",
"p_travel_sec",
"s_arrival_sample",
"s_status",
"s_weight",
"source_id",
"source_origin_time",
"source_origin_uncertainty_sec"
))
nmtso_files <- c("eigen.dat",
"hypo71.dat",
"jparam.dat",
"newloc.dat",
"picfil.dat",
"refloc.dat",
"stacrd.dat",
"temp_picfil.dat",
"velmod.dat")
matched_data <- stead_data %>%
mutate(
nmtso_files = if (stead_data == regex(pattern = "source*")) {
nmtso_files[1]
} else {
nmtso_files[4]
}
)