mardi 22 octobre 2019

Run if on multiple conditions, no error, but data doesn't change

I tried to impute missing data with median on conditions, no error but the data didn't change. Why and how can I make it work?

housing = read.csv('housingsample22.csv')

if (housing$Car == 0 && housing$Tunit == 1) 
   {housing$Car = median(housing$Car)}

if (housing$Landsize == 0 && housing$Tunit != 1) 
   {housing$Landsize = median(housing$Landsize)}

if (housing$BuildingArea == 0 && housing$TTHouse == 1)     
   {housing$BuildingArea = median(housing$BuildingArea[housing$TTHouse == 1])}

Aucun commentaire:

Enregistrer un commentaire