Home > Blockchain >  Adding a column using the if statement
Adding a column using the if statement

Time:09-22

For the sample data as given below, 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?

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