'How to replace a dataframe value with NA based on location?

This is a duplicate of the following question, as I'm trying to adapt it for my data...

[https://stackoverflow.com/questions/66236799/how-to-replace-a-value-with-na-based-on-two-conditions-in-r-dplyr][1]

Problem: I'm plotting a series of mean and standard deviation data but the lower errorbar at one site, exceeds the x-axis...

Aim: I want to repeat the standard deviation column but with the high SD value replaced with NA - then call on this new column to plot the lower errorbar vector (so it effectively only plots the upper errorbar for this site). Alternatively, if there is an easier way to only plot an upper errobar for the specific site, without modifying the data frame... great!?

Simplified data frame:

df$Site = c(1:3)

df$SD = c(0.74638, 1.82636, 0.63874)

I've tried the following code but it just reprints the same values in the new column:

df1.1 <- df %>% mutate(SD_s4 = ifelse(Site == "2" & SD == 1.82636, NA_real_, SD))
rna


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source