Unlist a column while retaining character(0) as empty strings in R

匆匆过客 提交于 2019-12-06 05:14:51

It's tough to say without more information about your data, but maybe this can be a solution for you, or at least point you into the right direction:

a <- list('A',character(0),'B')

> a
[[1]]
[1] "A"

[[2]]
character(0)

[[3]]
[1] "B"

> unlist(lapply(a,function(x) if(identical(x,character(0))) ' ' else x))
[1] "A" " " "B"

So in your case that should be:

df$general_RN <- unlist(lapply(df$general_RN,function(x) if(identical(x,character(0))) ' ' else x))

HTH

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!