Replacing a value in multiple columns in data.table

I have a large table with time series data (not in time series format), and I would like to replace certain values ​​with a simple line of code. Below you will find a sample table. I would like to replace NA with anything and 88888 by 0. Of course, this can be done column by column using a while loop. However, I think there is a simpler solution to this problem. Any suggestions?

Dataset example:

sample <- structure(list(Period = c("01-12-08", "01-01-09", "01-02-09", "01-03-09",
 "01-04-09", "01-05-09", "01-06-09", "01-07-09", "01-08-09", "01-09-09", "01-10-09",
 "01-11-09", "01-12-09", "01-01-10", "01-02-10"), Serie1 = c(NA, NA, NA, NA, NA, NA,
 NA, NA, NA, NA, NA, 6L, 88888L, 88888L, 88888L), Serie2 = c(NA, NA, NA, NA, NA, NA,
 20L, 88888L, 88888L, 88888L, 88888L, 88888L, 88888L, NA, NA), Serie3 = c(NA, NA,
 NA, NA, NA, NA, NA, NA, NA, 10L, 10L, 88888L, 88888L, 88888L, 88888L)), .Names =
 c("Period", "Serie1", "Serie2", "Serie3"), row.names = c(NA, -15L), class =
 c("data.table", "data.frame"))
+3
source share
1 answer
sample[is.na(sample)] <- ""
sample[sample == 88888] <- 0
+5
source

All Articles