Skip to content

Instantly share code, notes, and snippets.

@joelnitta
Created March 17, 2021 06:23
Show Gist options
  • Save joelnitta/09d4da1501632a44f659c315de843544 to your computer and use it in GitHub Desktop.
Save joelnitta/09d4da1501632a44f659c315de843544 to your computer and use it in GitHub Desktop.
nested dollar sign columns
library(tidyverse)
dat <- tibble(var = c("a_b", "c_d"))
split_vec_to_df <- function(x) {
tibble(
var_1 = str_split(x, "_")[[1]][[1]],
var_2 = str_split(x, "_")[[1]][[2]]
)
}
split_vec_to_df("a_b")
mutate(dat, split_var = map_df(var, split_vec_to_df))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment