R regex 正则表达式:从字符串中的逗号分隔值创建字符列表

R regex regular expression: create list of characters from comma-separated values in a string

假设我在 R 中有以下字符串:

x <- "one, two, three, four"

我想获取向量

c("one", "two", "three", "four")

是否可以使用正则表达式来做到这一点?我尝试了给定的示例 here 但没有任何效果。

stringr 包可以做到这一点...

library(stringr)
str_split("one, two, three, four", ", ")

基础 R 解决方案:

unlist(strsplit(x, ", "))

数据:

x <- "one, two, three, four"