Good day,
Suppose that I have this dataset that shows the capability and output of wind and gas generators, and it looks similar to this example table below:
Generation_Data = data.frame(Generator= c(1, 2, 3, 4, 5),
Fuel_Type = c('Gas', 'Wind', 'Wind', 'Gas', 'Wind'),
Available_Capacity = c(0, 11, 9, 0, 12 ),
Capability = c(50, 19, 18, 56, 20),
Output = c(50.5, 10, 7, 54, 10))
Note that "Available Capacity" for wind generators and "Capability" for gas generators essentially mean the same thing, and they represent the theoretical maximum amount of power the generators can produce.
I used mutate function below to calculate the difference between the theoretical generating capacity of each generator (i.e., "Available_Capacity" for wind generators and "Capability" for gas generators) and how much it actually generates (i.e., "Output").
library(dplyr)
Difference_Data <- Generation_Data %>%
mutate(Difference = case_when(
Fuel_Type == 'Wind' ~ (Available_Capacity - Output),
Fuel_Type == 'Gas' ~ (Capability - Output)
))
But I have these rare cases (Generator 1 in this example) where gas generators produce slightly more than their theoretical "Capability" and this causes the "Difference" to be negative. So I wanna add some codes that will make "Difference" for gas generators equal 0 if it's less than 0.
So in the aforementioned example, the Generator 1 has a difference of -0.5, but I want to make this equal 0 instead. Anyone know how to do this? Also, please note that I must do this without removing this "case_when" function!
Thank you in advance!