Hello,
In the first code chunk, I'm trying to use the dplyr ifelse() function to calculate a summary mean value based on a condition. The code runs, but I am getting incorrect values returned (the correct values are produced in the second chunk of code, by filtering the df first, then running the summary). The sum ifelse() works fine to get the count of rows passing the condition, and they match the values returned in the filtered code chunk.
I suspect I'm doing something wrong with the second argument of the ifelse() and have unsuccessfully tried several options, and would appreciate any help.
If you want to filter out the flights with departure delays less than 3.00, have ifelse() set the value to NA, not zero. The zero values will be included in the calculation of the mean, giving a much smaller value. Setting them to NA and then na.rm = TRUE will remove them from the calculation.
I am not 100% sure, but including print() at the end of the pipe does not make sense. How can it print an object that has not been assigned yet? When I ran your code it caused an error. I just wrapped the code in (), which means it will both assign the output to a name and print it.