mercredi 5 décembre 2018

R - if_else assign na value

I have a dataframe in R. My goal is to create a new column with if_else statement. If the value in a row is equal to the string "company", then the value of this new column will be the value from data column. Otherwise, I'd like to assign to if NA value.

I don't know how to achieve that, my code below does not work. Because of a different data type.

  active_labels <- data %>%
      mutate(start_date = if_else(type == "company", date, NA) 


Error in mutate_impl(.data, dots) : 
  Evaluation error: `false` must be type double, not logica

Aucun commentaire:

Enregistrer un commentaire