This is my first question, so I will attempt to give as much detail as possible.
I am attempting to create a function in which I can produce a new column containing "1" or "0" as my output based on whether or not the original column had a date listed or it had no value. Below is a small example of what I am trying to achieve:
Column 1 New Column
Obs.1 4/23/2012 1
Obs.2 0
Obs.3 1/23/2016 1
I am not sure on how to go about doing this. I have attempted to use tapply()
and ifelse()
in conjunction, but have not had any workable code. This is sort of what I am going for:
TextToNumb <- function(df$column){
Ifelse(df$column > 0, 1, 0)
return(df$newcolumn
}
I would appreciate any help, thanks!
Aucun commentaire:
Enregistrer un commentaire