In R data.table, how to replace NA value more efficiently

Viewed 40

In R data.table, how to replace NA value more efficiently ? Thanks!

test_data <- data.table(x=c('a','b','c'),y=c('d','e', NA),a=c(1:3),b=c(1,7,NA),c=c(NA,3,NA))

below code can work but very slow , because the actual data is more than 3 million rows

  test_data %>% mutate(across(where(is.numeric),function(x) str_replace_na(x,0)))
0 Answers
Related