samedi 5 septembre 2020

R function for an ifelse mutate statement

I am trying to write a script that says if a variable is greater than 0, use this equation, if not use this variable in place.

My code:

risk_count_eq <- risk_count - risk_count_2
    mutate(risk_count_1 = ifelse (risk_count_2 > 0, risk_count_eq, if else(risk_count_2 ==0, risk_count)

This is what is in my output at the end: risk_count_1 not being assigned risk_count if risk_count_2 is equal to zero

Aucun commentaire:

Enregistrer un commentaire