简体   繁体   中英

R cannot find specific function in a package

I'm using the randomForest package (v 4.6-7) in R (v 2.15.3) and can easily use the function randomForest to create a model. However, when I try to predict on my test set, the predict.randomForest function cannot be found. I've also tried plotting with plot.randomForest only to get the same error, "could not find function."

I've already tried reinstalling the package (figuring maybe it was out of date) and made sure the spelling is absolutely correct. I cannot figure out what's causing this error, any ideas?

It appears that the functions of interest are not exported from the package.

If you use ls(package:randomForest) you'll get a list of the exported functions.

If you want to see all the functions available the use: ls(getNamespace("randomForest"), all.names=TRUE) . Thanks @Joshua. You'll see the functions you want there.

In order to refer to one of them explicitly, use: randomForest:::predict.randomForest() or just make a object which inherits the class 'randomForest' and call predict() on it directly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM