R: Split character column and create two new ones

后端 未结 4 1841
清歌不尽
清歌不尽 2021-01-25 14:37

R users

I have a data frame similar to this:

a <- c(\"John, 3 years\") 
b <- c(\"Mokobe, 11 years\")
c <- c(\"Ivan\")
df <- rbind(a,b,c)
df
          


        
4条回答
  •  离开以前
    2021-01-25 15:03

    # This should work
    library(stringr)
    
    a <- c("John, 3 years") 
    b <- c("Mokobe, 11 years")
    c <- c("Ivan")
    df<- rbind(a,b,c)
    
    df<- str_split_fixed(df, ",", 2)
    

提交回复
热议问题