1

Trying to replace values in a column with NA using the condition: if sensor is equal to 2032, and date is less than 2019-01-29 replace all values in column "temperature" with NA.

I have tried the code below but getting an error "argument "true" is missing, with no default"

filter(if_else(sensor == 2032 & date(date_time) < 2019-01-29), NA, temperature)

I have seen this solution but could not get it to work for me:

Replace certain values of a vector with NA

alistaire
  • 42,459
  • 4
  • 77
  • 117
hizjamali
  • 35
  • 5
  • 1
    `dplyr::filter` subsets rows, but doesn't assign; you'd need `mutate` – alistaire Jul 04 '19 at 05:51
  • Thanks @alistaire; this worked for me: ```mutate(temperature = ifelse(sensor == == 2032 & date(DateTime) < "2019-01-29", NA, temperature))``` if_else is returning an error though something to do with data types being different. Thanks – hizjamali Jul 04 '19 at 22:20
  • Yeah, `if_else` cares about which `NA` you use, so you may need `NA_integer_` or `NA_real_`. And your code looks like it has two sets of `==` for some reason. – alistaire Jul 04 '19 at 22:46
  • Thanks alistaire! == is a typo that I can't edit here now – hizjamali Jul 05 '19 at 03:50

0 Answers0