I have 2 different nomenclatures and want to split the patient ID and timepoint
Original dataframe
df <-c(“patient_id_and_timepoint”, “12345 V1”, “101-123-V1)
patient_id_and_timepoint |
---|
12345 V1 |
101-123-V1 |
Desired dataframe
| patient_id | timepoint |
| ——– | ————– |
| 12345 | V1 |
| 101-123 | V1 |
I am close by doing this:
sampledata <- df %>% mutate(timepoint=case_when(str_detect(patient_id_and_timepoint, " V")~str_split_fixed(df$patients_id_timepoint, ' ', 2), str_detect(patients_id_timepoint, "-V")~str_split_fixed(df$patients_id_timepoint, '-V', 2)))