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

前端 未结 6 778
不思量自难忘°
不思量自难忘° 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条回答
  •  温柔的废话
    2020-12-09 18:06

    It is not taking the mean of the entire Sepal.Length column; only the 1 column that you have chosen.

    Rather use:

    ww[is.na(Sepal.Length) , Sepal.Length:= mean(ww$Sepal.Length, na.rm=TRUE)]
    

提交回复
热议问题