0

I'm trying to remove the text " 12:00:00 AM" from the string e.g: "4/12/2016 12:00:00 AM" from the column "ActivityDate"

I'm using this pipe:

Sleep <- sleepDay_merged %>%
  rename('ActivityDate' = 'SleepDay') %>%
  gsub("12:00:00 AM","",'ActivityDate')

And I get this error:

In addition:

Warning message:
In sub(., "12:00:00 AM", "", "ActivityDate") :
  argument 'pattern' has length > 1 and only the first element will be used

Could please help me?

Cheers

Prabhakaran
  • 3,900
  • 15
  • 46
  • 113

1 Answers1

0

You have some syntax issues. Use gsub (or just sub if you have only one replacement) in mutate. Also, the column ActivityDate should not be in quotes (""). Try with -

library(dplyr)

Sleep <- sleepDay_merged %>%
  rename('ActivityDate' = 'SleepDay') %>%
  mutate(ActivityDate = gsub("12:00:00 AM","",ActivityDate))
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213