I\'d like to create a new variable based on condition imposed on the original variable. Let\'s say
You can do this using either ifelse or which. With ifelse you don't need to create the column of NAs first:
mydata$newvar <- ifelse(mydata$var < 10, mydata$var, NA)
If you have already created the column of NAs, this will work:
mydata$newvar[which(mydata$var < 10)] <- mydata$var[which(mydata$var < 10)]