I would like to create a new variable with the values to be determined by the corresponding values of two existing variables. My data set is similar to the one below:
aid <- c(1,2,3,4,5)
temp <- c(38,39,NA,41,NA)
surv1 <- c(5,8,0,6,9)
data <- data.frame(aid,temp,surv1)
Now, I would like to create a new variable called surv2. That is, if temp is NA then surv2 should also be an NA; and if temp is not NA then surv2 should take the value of surv1
#The final data should look like this:
aid <- c(1,2,3,4,5)
temp <- c(38,39,NA,41,NA)
surv1 <- c(5,8,0,6,9)
surv2 <- c(5,8,NA,6,NA)