R: Split character column and create two new ones

后端 未结 4 1836
清歌不尽
清歌不尽 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:13

    with tidyr library:

    library(tidyr)
    df <- as.data.frame(rbind(a,b,c), stringsAsFactors=F)
    separate(df, V1, c("name", "age"),sep = ",")
    

提交回复
热议问题