How can I extract all text after first space in a column where data is something like this
structure(list(value = c("1.1.a Blue sea", "1.2.a Red ball")), row.names = c(NA, -2L), class =c("tbl_df", "tbl", "data.frame"))
so I get a new column with just
Blue sea
Red ball
>Solution :
You can use the following code to select all text after the first white space:
sub("^\\S+\\s+", '', df$value)
Output:
[1] "Blue sea" "Red ball"
You can just use this to create it as a new column:
library(dplyr)
df %>%
mutate(new_value = sub("^\\S+\\s+", '', value))
Output:
# A tibble: 2 × 2
value new_value
<chr> <chr>
1 1.1.a Blue sea Blue sea
2 1.2.a Red ball Red ball