1

Through out this process:

library("spacyr")
library("dplyr", warn.conflicts = FALSE)

mytext <- data.frame(text = c("test text", "section 2 sending"), id = c(32,41))

is it possible to melt the input dataframe my text using as separation for every row the space between terms?

Example output:

32 test
    32 text
    41 section
    41 2
    41 sending
demia
  • 39
  • 5

2 Answers2

0

Easy to to do with the tidyr library

mytext <- data.frame(text = c("test text", "section 2 sending"), 
                     id = c(32,41))

tidyr::separate_rows(mytext, text)
#> # A tibble: 5 x 2
#>   text       id
#>   <chr>   <dbl>
#> 1 test       32
#> 2 text       32
#> 3 section    41
#> 4 2          41
#> 5 sending    41
Chuck P
  • 3,862
  • 3
  • 9
  • 20
0

We can use cSplit

library(splitstackshape)
cSplit(mytext, "text", sep=" ", "long")
#      text id
#1:    test 32
#2:    text 32
#3: section 41
#4:       2 41
#5: sending 41
akrun
  • 874,273
  • 37
  • 540
  • 662