0

I have a column that looks like:

date
12/04/33 12:34 24
12/03/22 12:43 26
11/01/24 11:22 42

I want to strip everything after the first space so that my column looks like:

date
12/04/33 
12/03/22
11/01/24 

Does anyone know how to do this simply? Perhaps using stringr?

CheckThis
  • 49
  • 4

1 Answers1

0
data %>%
  mutate(
    stringr::str_remove(date, ' .*')
  )

or

data %>%
  mutate(
    stringr::word(date, 1)
  )
Baraliuh
  • 2,009
  • 5
  • 11
  • Thanks! But oddly it is not working. The code runs but then when I `view(data)`, the column has not updated. Any ideas? – CheckThis Apr 22 '22 at 20:38
  • @CheckThis You need to assign the output of the above code to data with `-> data`. It seems that you have fundamental gaps in your knowledge of the R programming language and would benefit more from reading a tutorial. See the [R tag wiki](https://stackoverflow.com/tags/r/info) for some great resources. – Ian Campbell Apr 22 '22 at 20:50