split character data into numbers and letters

后端 未结 7 1744
没有蜡笔的小新
没有蜡笔的小新 2020-12-02 15:45

I have a vector of character data. Most of the elements in the vector consist of one or more letters followed by one or more numbers. I wish to split each element in the

7条回答
  •  隐瞒了意图╮
    2020-12-02 16:45

    Since none of the previous answers use tidyr::separate here it goes:

    library(tidyr)
    
    df <- data.frame(mycol = c("APPLE348744", "BANANA77845", "OATS2647892", "EGG98586456"))
    
    df %>%
      separate(mycol, 
               into = c("text", "num"), 
               sep = "(?<=[A-Za-z])(?=[0-9])"
               )
    

提交回复
热议问题