Home > Net >  adding a column using if statement
adding a column using if statement

Time:09-22

For the blow sample data, I am trying to use the if statement to create a new column called newcol. I would like to condition the newcol on the Letter column such that if the Letter is NA then newcol is TRUE. How can I do this using if command without loading any libraries?

Thanks,

MRR

    M <- data.frame(c("A","B","C",NA),c(5,100,NA,60))

names(M) <- c("Letter","Number")

CodePudding user response:

Try using is.na:

M$newcol <- is.na(M$Letter)
  • Related