我有以下字符串:
employees
[1] "e1 e2 e3 e4 e5"
我想将其分为五个不同的元素,例如:
"e1" "e2" "e3" "e4" "e5"
我尝试使用以下行来解决此问题:
strsplit(employees,"" )
产生以下结果:
[1] "e" "1" " " "e" "2" " " "e" "3" " " "e" "4" " " "e" "5"
我该怎么做才能解决问题并避免字符和数字分开?
谢谢!
答案 0 :(得分:0)
您需要按空格分割,这似乎是数据中的分隔符:
x <- "e1 e2 e3 e4 e5"
unlist(strsplit(x, " "))
[1] "e1" "e2" "e3" "e4" "e5"