Replace NAs with mean of the same column of a data.table

前端 未结 6 781
不思量自难忘°
不思量自难忘° 2020-12-09 17:42

I want to replace NAs present in a column of a DATA TABLE with the mean of the same column. I am doing the following. But it is not working.

ww <- data.ta         


        
6条回答
  •  萌比男神i
    2020-12-09 17:55

    na.aggregate in the zoo package replaces NAs with the mean of the non-NAs in the same column:

    library(zoo)
    
    ww[, Sepal.Length := na.aggregate(Sepal.Length)]
    

提交回复
热议问题