Suppose df
contains a variable v
, from which I want to mutate three variables: anything before "(" will be the value of the first variable; anything after "(" but before space will be the value of the second variable; anything after space will be the value of the third variable.
df
v |
---|
mean(air_temperature PT30M) |
max(soil_temperature PT5M) |
df_wanted
method | datatype | period |
---|---|---|
mean | air_temperature | PT30M |
max | soil_temperature | PT5M |
library(tidyverse)
# Toy data
df <- tibble(
v = c("mean(air_temperature PT30M)", "max(soil_temperature PT5M)")
)
# What I tried
df |>
separate(v, into = c("method", "dt_period"), sep = "(")
#> Warning in gregexpr(pattern, x, perl = TRUE): PCRE pattern compilation error
#> 'missing closing parenthesis'
#> at ''
#> Error in gregexpr(pattern, x, perl = TRUE): invalid regular expression '('
Created on 2022-12-17 with reprex v2.0.2