I'm importing data which I need to separate into two columns. I'm having trouble to make the separator to match the first white space, because using \\s
, eliminates the rest of the column. Normally I would use a split operator or remove the g
flag on a regex, but here I don't know how to solve it.
So, as an example:
fruits <- data.frame(
col = c("apples and oranges and pears and bananas",
"pineapples and mangos and guavas")
)
separate(fruits, col, into = c("first", "rest"), sep = "\\s")
first rest
1 apples and
2 pineapples and
Warning message:
Expected 2 pieces. Additional pieces discarded in 2 rows [1, 2].
I would have expected:
first rest
1 apples and oranges and pears and bananas
2 pineapples and and mangos and guavas