Goal
Not sure why I haven't been able to get this to work but I have a data frame similar to this overly simplified example,
type sec station wt
1 0 43 DAG 0.80
2 1 92 DAG 0.24
3 31 31 DAG NA
4 0 22 CBET 0.92
5 1 52 CBET 0.10
6 31 61 CBET NA
and I am trying to get, essentially, to here
station sec_0 wt_0 sec_1 wt_1 sec_31 wt_31
1 DAG 43 0.80 92 0.24 31 NA
2 CBET 22 0.92 52 0.10 61 NA
I know it's probably super simple but when I've tried putting conditional statements inside the summarize it doesn't want to work.
REPREX
reprex_data <- read_csv(file = "https://gitlab.com/Bryanrt-geophys/sac2eqtransformr/-/raw/master/sample_data/pre_stead.csv", col_names = T)
reprex _data %>%
group_by(station) %>%
summarize(
sec_0 = if(type == 0){
sec
} else (NA),
wt_0 = if(type == 0){
wt
} else (NA),
sec_1 = if(type == 1){
sec
} else (NA),
wt_1 = if(type == 1){
wt
} else (NA),
sec_31 = if(type == 31){
sec
} else (NA),
wt_31 = if(type == 31){
wt
} else (NA)
)
This is just a basic example to avoid long convoluted instructions. I have provided my real data below. Any and all help is appreciated. I am trying to split the columns sec, wt, ain, obs_arv, obs_trv, resid, and sta_cor.
Actual Data
actual_data <- read_csv(file = "https://gitlab.com/Bryanrt-geophys/sac2eqtransformr/-/raw/master/sample_data/pre_stead.csv", col_names = T)