0

Here there's an example:

car <- data.frame(matrix(c(2,NA,5,NA,7,6), nrow=3, ncol=2, byrow = FALSE))
colnames(car) <- c("a","b")

How can I write this part without repeating the code?

car$a[is.na(car$a)] <- 0
car$b[is.na(car$b)] <- 0
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
jeff
  • 323
  • 1
  • 7

0 Answers0