Replacing all missing values in R data.table with a value

前端 未结 4 1607
清歌不尽
清歌不尽 2020-12-04 14:05

If you have an R data.table that has missing values, how do you replace all of them with say, the value 0? E.g.

aa = data.table(V1=1:10,V2=c(1,2,2,3,3,3,4,4,         


        
4条回答
  •  有刺的猬
    2020-12-04 14:20

    The specific problem OP is posting could also be solved by

    tt[is.na(X), X := 0]
    

提交回复
热议问题