View source: R/separate-longer.R
separate_longer_delim | R Documentation |
Each of these functions takes a string and splits it into multiple rows:
separate_longer_delim()
splits by a delimiter.
separate_longer_position()
splits by a fixed width.
separate_longer_delim(data, cols, delim, ...)
separate_longer_position(data, cols, width, ..., keep_empty = FALSE)
data |
A data frame. |
cols |
< |
delim |
For |
... |
These dots are for future extensions and must be empty. |
width |
For |
keep_empty |
By default, you'll get |
A data frame based on data
. It has the same columns, but different
rows.
df <- tibble(id = 1:4, x = c("x", "x y", "x y z", NA))
df %>% separate_longer_delim(x, delim = " ")
# You can separate multiple columns at once if they have the same structure
df <- tibble(id = 1:3, x = c("x", "x y", "x y z"), y = c("a", "a b", "a b c"))
df %>% separate_longer_delim(c(x, y), delim = " ")
# Or instead split by a fixed length
df <- tibble(id = 1:3, x = c("ab", "def", ""))
df %>% separate_longer_position(x, 1)
df %>% separate_longer_position(x, 2)
df %>% separate_longer_position(x, 2, keep_empty = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.