How to set up data for "ranger" in R. Error: Missing data in columns

2.6k Views Asked by At

Code:

ranger(outcome~., data, num.trees=500, probability=TRUE)

Error: Missing data in columns

Is there a format that the data needs to be in? How to get past this error?

1

There are 1 best solutions below

0
On BEST ANSWER

You need to remove NAs Example:

ranger(outcome~., data[complete.cases(data),], num.trees=500, probability=TRUE)

Other methods use packages like mice or miceFast to impute (fill NA). Other simple solution to impute the data with random data (from each column).

data_cs = data.frame(Map(function(x) Hmisc::impute(x,'random'), data))
ranger(outcome~., data_cs, num.trees=500, probability=TRUE)