In R, how do I translate one record with a single comma-separated field into multiple records?

前端 未结 2 1734
不思量自难忘°
不思量自难忘° 2021-01-23 15:43

I\'m working in R.

I have a dataset in which some records contain a list of cities and counties instead of just one city or county. I\'m looking for a way to transpose

2条回答
  •  迷失自我
    2021-01-23 16:26

    You can use the function colsplit in package reshape2:

    x <- c("a, b", "c, d", "e")
    library(reshape2)
    colsplit(x, ",", names=c("City", "County"))
    
      City County
    1    a      b
    2    c      d
    3    e       
    

提交回复
热议问题