0

I'm running into a problem where I have mutated a new column

lowCOXdata %>%
  mutate(IL1bLoworHigh = case_when(Adjusted.Average..IL1b < 2.30 | Adjusted.Average..IL1b == NA ~ 1,
      Adjusted.Average..IL1b > 2.30 ~ 2)
  )

called IL1bLoworHigh in dataframe called lowCOXdata, and what's strange is that the new column is created and shown in the data viewer, but not the environment and data frame. In the data viewer, it says that the number of columns is 9, but on the right hand side in the environment the number of variables is 8. See picture below: 9 columns on the left side but only 8 variables

Amy Zhang
  • 11
  • 1
  • 3
  • Can you show a sample of your data frame as an example? You can use `dput` to regenerate your data frame. This way, we can easily copy and check your dataset – Ross_you Nov 18 '20 at 02:23
  • You have to assign results to modify objects. If `x <- 1`, `x + 1` shows `2` but `x` is unchanged. `x <- x + 1` to modify `x`. `lowCOXdata <- lowCOXdata %>% mutate...` to modify the object. – Gregor Thomas Nov 18 '20 at 02:27
  • 1
    Also, `== NA` is an antipattern. Use `is.na()` instead, change to `Adjusted.Average..IL1b < 2.30 | is.na(Adjusted.Average..IL1b) ~ 1`. – Gregor Thomas Nov 18 '20 at 02:28

0 Answers0