I have a dataframe with an ID column and several columns of survey data. We now know that there was a glitch in the survey instrument, so entries are invalid for several consecutive columns for participants with IDs 3 through 11. We want to keep the data from these participants that IS valid, but change data in compromised columns from the current values to 99s. I can't share the survey data, so will explain what I'm hoping for using the iris dataset:
data("iris")
iris =
iris %>%
mutate(id = row_number())
The above code of course yields the following:
So to solve my problem, I'm pretending entries with IDs 3 through 11 have compromised data for Sepal.Length, Sepal.Width, and Petal.Length, but that Petal.Width and Species are fine and should be left alone. How can I convert data for these columns to "99" in the specified rows, yielding the following?:
I know that I could do a long series of ifelse() statements, but that there's got to be a more straightforward approach. Any help is greatly appreciated!