0

I have the following string:

employees

[1] "e1 e2 e3 e4 e5"

and i want to separate it in five different elements, like this:

"e1" "e2" "e3" "e4" "e5"

I tried to solve this problem using the following line:

strsplit(employees,"" )

which yields this result:

[1] "e" "1" " " "e" "2" " " "e" "3" " " "e" "4" " " "e" "5"

What can i do to solve the problem and avoid the separation of characters and numbers?

Thank you!

Martin
  • 41
  • 7

1 Answers1

0

You need to split by space, which appears to be the separator in your data:

x <- "e1 e2 e3 e4 e5"
unlist(strsplit(x, " "))

[1] "e1" "e2" "e3" "e4" "e5"
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360