I need to make special rules for some data that I have (if a value is <= 0.1 then make it missing it's an error) but I only want to do it for certain categories.
My data looks like this
Category value
A 0.9
A 0.001
A 0.3
B 0.01
B 0.8
C 0.01
C 0.01
C 0.2
C NA
I want this
Category value
A 0.9
A 0.001
A 0.3
B NA
B 0.8
C NA
C NA
C 0.2
C NA
My code looks like this:
want<- Mydata %>%
mutate(value2= if_else(!is.na(value) &
value<=0.1 &
Category=='B' ||
!is.na(value) &
value<=0.1 &
Category=='C',
as.numeric(NA), value ) )
But I get this error message:
Error: `true` must be length 1 (length of `condition`), not 1245
My understanding is that || is a logical and & is an individual so essentially I want to say
IF (NOT NA AND <=15 AND in category B) OR (NOT NA AND <=15 AND in category C) then make the value NA else use the original value.
I don't understand why I get this error do I misunderstand | vs || and & vs &&?