Hi,
I am running the following code:

ret <- data.frame(V1=rep(NA,dim(hhm)[1]))

years <- c("grade04","grade05","grade06","grade07","grade08")

for(i in 1:(length(years)-1)){
  ret[,i] <- ifelse(hhm[,years[i+1]]==hhm[,years[i]],1,0)}

ret$ret.s <- ifelse(ret$V1==1 | ret$V2==1 | ret$V3==1 | ret $V4==1,c("1"),c("0"))

However, when it encounters an 'NA' in these variables it assigns ret.s an 'NA'. What I want it to do is either assign a 0 or a 1. A 1 should occur if an individual has the same value for grade04 & grade05, grade05 & grade06, and so on. If the individual does not have this I would like to assign a value of 0. However, when it encounters a NA it assigns an NA. How can I overcome this?

Thanks,
Chris

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to