comma separated string to list in r

﹥>﹥吖頭↗ 提交于 2019-12-03 23:17:32

This is a basic strsplit problem:

x <- "a,b,c"
as.list(strsplit(x, ",")[[1]])
# [[1]]
# [1] "a"
# 
# [[2]]
# [1] "b"
# 
# [[3]]
# [1] "c"

strsplit creates a list and the [[1]] selects the first list item (we only have one, in this case). The result at this point is just a regular character vector, but you want it in a list, so you can use as.list to get the form you want.

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