0

I want to split up all words in a column so that they get one row each (where the rest of the data columns then gets repeated).

#Example Data

example_words <- c("one two three", "four five", "six")
values <- c(1, 2, 3)
tibble_test <- tibble(example_words, values)


# Expected output

example_words <- c("one",  "two", "three", "four", "five", "six")
values <- c(1, 1, 1, 2, 2, 3)

tibble_test <- tibble(example_words, values)

Thanks in advance

Oscar Kjell
  • 1,599
  • 10
  • 32

1 Answers1

1

Does this work:

library(dplyr)
library(tidyr)
tibble_test %>% separate_rows(example_words, sep = ' ')
# A tibble: 6 x 2
  example_words values
  <chr>          <dbl>
1 one                1
2 two                1
3 three              1
4 four               2
5 five               2
6 six                3
Karthik S
  • 11,348
  • 2
  • 11
  • 25