Split string by final space in R

前端 未结 1 1977
日久生厌
日久生厌 2021-01-06 21:31

I have a vector a strings with a number of spaces in. I would like to split this into two vectors split by the final space. For example:

vec <- c(\'This i         


        
相关标签:
1条回答
  • 2021-01-06 22:01

    Here is one way using a lookahead assertion:

    do.call(rbind, strsplit(vec, ' (?=[^ ]+$)', perl=TRUE))
    #      [,1]           [,2]     
    # [1,] "This is"      "one"    
    # [2,] "And"          "another"
    # [3,] "And one more" "again" 
    
    0 讨论(0)
提交回复
热议问题