Created
March 17, 2021 06:23
-
-
Save joelnitta/09d4da1501632a44f659c315de843544 to your computer and use it in GitHub Desktop.
nested dollar sign columns
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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