Creating new columns in data.table

New columns can be created in data.table using the := notation, as shown:

dstate[,IncomeGreaterThan5000:=Income>5000] # We will add a column IncomeGreaterThan5000 in-place using := 
 
# Adding multiple columns 
 
dstate[,c("IncomeGreaterThan5000","AreaLessThan5000"):=list(Income>5000,Area<5000)] # We will add a column IncomeGreaterThan5000 in-place using := 
 
# alternatively, we can also use `:=` 
 
dstate[,`:=`(IncomeGreaterThan5000=Income>5000,AreaLessThan5000=Area<5000)] # We will add a column IncomeGreaterThan5000 in-place using :=  
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.134.151