I'm working with a time series that has a couple of thousands of row, but here's a small sample of the two columns in question I want to talk about:
data <- data.frame(
Precipitation = sample(c("0.12", "0.14", "0.08", "0.30", "0.10", "0.40", "1.6", "0", "0")),
Character = sample(c("A", "B", "C", "D", "E", "F", "G", "H", "I")))
Each value in the Precipitation column corresponds to the letter in the Character column (i.e. 0.12 -> A, 0.14 -> B, etc.).
Each of those letters represents a potential "change" that needs to be done to the values in the Precipitation column, which is:
- Precipitation values with letter A are fine as is
- Precipitation values with letter B need to be divided by 2
- Precipitation values with letter C need to be divided by 3
- Precipitation values with letter D need to be divided by 4
- Precipitation values with letter E need to be divided by 2
- Precipitation values with letter F need to be divided by 4
- Precipitation values with letter G need to be divided by 4
- Precipitation values with letter H are fine as is
- Precipitation valued with letter I are fine as is
Now, I want to make a new column using dplyr to do the divisions noted by the Character column onto the Precipitation column while also bringing over the corresponding A, H, and I rows that do not require any changes. What would the code look like to do this?
Thank you for your help! It is much appreciated.