I'm fairly new to R, and I'm trying to write a formula for a new column 'w_1yr'
(within 1yr), using two other columns in my dataframe
: enroll_yr
(year of enrollment) and lab_yr
(year of lab drawn done).
Basically, I'm trying to say that if the lab_yr
is within 1 yr of the enroll_yr
then w_1yr
=1, otherwise, 0.
The following is what I have so far, but still it is not correct.
df$w_1yr <- ifelse(df$lab_yr <= 'enroll_yr', 1, ifelse(df$lab_yr > 'enroll_yr', 0, NA))
(sorry for some reason I can't copy/paste from the console, so had to write it out)
If anyone can help me out, that would be great! Thanks!