df <- data.frame(x=c(1, 2, NA, NA)) df$foo1[!is.na(df$x)] <- 777 df[["foo2"]][!is.na(df$x)] <- 888 `<-`(df$foo3[!is.na(df$x)], 999) `[[`(df, "foo4")[!is.na(df$x)] <- 0 `<-`(`[[`(df, "foo5")[!is.na(df$x)], 1) df
To embed this project on your website, copy the following code and paste it into your website's HTML: