New conditional variable converts the same condition as NA´s

Hey there,

I try to create a new conditional variable. It also worked great until I noticed that one and the same condition gives me once the right and once a NA.


# The analysis should be done for each 4ISS category
# 1. 4ISS = 0 = no stroke, 2. 4ISS = 1 - 7 = IVT, 3. 4ISS >= 3 = IVT and EVT

stroke_angel_data %>% 
  # give the 4ISS Scores a meaning in a new column
  mutate(classification_according_to_4ISS = case_when(
                                ly_rd4iss == "0" ~ "no Stroke", 
                                ly_rd4iss == c("1", "2") ~ "IVT",
                                ly_rd4iss >= "3" ~ "IVT and EVT")) %>% 
  # remove NA´s from 4ISS column
  select(ly_rd4iss, classification_according_to_4ISS) %>% 
  View()

And the result is this table:


In line 26 the value "2" was correctly rewritten to "IVT".
In line 29 however, the value "2" was rewritten as "NA".

Has anyone had a problem like this before?

I also tried it with different data types.

By the way:
Why has the new mutated column a new variable label. This is one of another variable which has nothing to do with the calculation :exploding_head:
The variable label of ly_rd4iss is wrong as well, although its correct in the original dataset.

Thank you and cheers,
Oli

you will see that in R

"2" == c("1", "2")

evaluates to FALSE TRUE, i.e. it is evaluated each time according whats on the right.
you probably want to use the %in% operator

"2" %in% c("1", "2")

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.