0

I have some data with names I'm trying to rename based on certain date ranges. For now I don't have an end date, but in the future there will be so it would be nice to have both options. I'm fine converting date back to date if ifelse() coerces it into numeric format unless there is a better way. Do I just have to convert to numeric first and figure out which numbers correspond to my date range, run ifelse(), then convert back to date when done? I tried to get some insight from this but i'm not sure if it will work for me. Ifelse statement in R with multiple conditions

structure(list(Serial = c("580300", "380201", "380201", "480862", 
"480862", "480862"), Name = c("Gomex", "Clammy", 
"Clammy", "Channel Islands", "Channel Islands", "Channel Islands"
), Date = structure(c(1476928800, 1553619600, 1476932400, 1503777600, 
1476936000, 1604070000), class = c("POSIXct", "POSIXt"), tzone = "")), row.names = c(NA, 
6L), class = "data.frame")

I'm trying to do something like this...

vue$Name <- ifelse(vue$Serial == "480862" & Date >= "2019-8-23 10:00:00", "newname", vue$Name)
Error in Date >= "2019-8-23 10:00:00" : 
  comparison (5) is possible only for atomic and list types
Johnny5ish
  • 295
  • 1
  • 2
  • 12
  • I wasn't able to reproduce your original error but I think you were missing some extraction operators `$` and inconsistent column names in your attempt `vue$name <- ifelse(vue$Serial == "480862" & vue$Date >= "2019-08-23 10:00:00", "newname", vue$Name)` – EJJ Jan 27 '21 at 18:50
  • @EJJ You are correct, thanks for picking that up, i fixed the typos but the same error remains. – Johnny5ish Jan 27 '21 at 18:53

1 Answers1

0

I found the problem vue$Name <- ifelse(vue$Serial == "483689" && vue$Date >= "2019-8-23 10:00:00", "newname", vue$Name)

I was missing the second & and vue$ before Date

Johnny5ish
  • 295
  • 1
  • 2
  • 12