This may not solve your memory issue:
# with randomForest:
rf <- randomForest(
x = training[, c("B2", "B3", "B4")],
y = as.factor(training$class),
importance = TRUE,
ntree = 2000,
na.action = na.omit
)
# With ranger
install.packages(ranger, repos = "http://cran.r-project.org")
library(ranger)
# remove missing vlaues before this call
rf_2 <- ranger(
as.factor(class) ~ B2 + B3 + B4,
data = training,
importance = "impurity",
num.trees = 2000
)