In a dataframe, when I replace NA with 0 using obt[is.na(obt)] <- 0
, the column type changes from integer to numeric.
How can I avoid that?
Sample data:
obt <- structure(list(Date = structure(c(19677, 19678, 19679, 19680,
19681, 19682, 19683, 19684, 19685, 19686), class = "Date"), Title = structure(c(NA,
NA, 3L, 3L, NA, NA, NA, 3L, NA, NA), levels = c("A", "D", "L",
"C"), class = "factor"), Units = c(NA, NA, 2L, 1L, NA, NA, NA,
1L, NA, NA)), row.names = c(NA, 10L), class = "data.frame")
New contributor
Ben is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.