You can use extract
from tidyr
package where you can specify regular expressions to split the column:
library(tidyr)
extract(df, Time, into = c("Column", "Time"), "(.*)\\s(\\S+)")
# Column Time
# 1 Week End 07-01-10
# 2 Week End 07-02-10
Use (.*)\\s(\\S+)
to capture two groups and split on the space which is followed by a group which contains no space \\S+
.
If you want to use stringr
package, you can use str_match
function with similar functionality:
stringr::str_match(df$Time, "(.*)\\s(\\S+)")[, 2:3]
# [,1] [,2]
# [1,] "Week End" "07-01-10"
# [2,] "Week End" "07-02-10"
strsplit
also works if you specify the space to be the one before the digit, here ?=
stands for look ahead and \\d
is a abbreviation for digits and is equivalent to [0-9]
:
do.call(rbind, strsplit(df$Time, "\\s(?=\\d)", perl = T))
# [,1] [,2]
# [1,] "Week End" "07-01-10"
# [2,] "Week End" "07-02-10"