After checking the original data in Excel for blanks and running Summary(cm3) to identify any null values in my data, I'm unable to identify an instances. Yet when I attempted to use the data in Random Forest, I get the following error. Is there something that Random Forest is reading as null which is not actually null? Is there a better way to check for this?> library(randomForest) > system.time(+ rf1 <- randomForest(as.matrix(cm3[,c(2:length(colnames(cm3)))]), + cm3[,1],data=cm3,ntree=50) + ) *Error in randomForest.default(as.matrix(cm3[, c(2:length(colnames(cm3)))]), : NA/NaN/Inf in foreign function call (arg 1) In addition: Warning message: In storage.mode(x) <- "double" : NAs introduced by coercion Timing stopped at: 1.33 0.01 1.35 * Thanks in advance, Mike -- View this message in context: http://r.789695.n4.nabble.com/Random-Forest-Reading-N-A-s-I-don-t-see-them-tp4201546p4201546.html Sent from the R help mailing list archive at Nabble.com.
R. Michael Weylandt <michael.weylandt@gmail.com>
2011-Dec-15 20:02 UTC
[R] Random Forest Reading N/A's, I don't see them
Use str() on your object and attach the result. For even faster help, use dput() on a *small* sample of your data to make the problem reproducible. My guess is that there are characters or, less likely, factors lurking about... Michael On Dec 15, 2011, at 2:39 PM, Lost in R <michael.hartye at principiscapital.com> wrote:> After checking the original data in Excel for blanks and running Summary(cm3) > to identify any null values in my data, I'm unable to identify an instances. > Yet when I attempted to use the data in Random Forest, I get the following > error. Is there something that Random Forest is reading as null which is not > actually null? Is there a better way to check for this? > >> library(randomForest) >> system.time( > + rf1 <- randomForest(as.matrix(cm3[,c(2:length(colnames(cm3)))]), > + cm3[,1],data=cm3,ntree=50) > + ) > *Error in randomForest.default(as.matrix(cm3[, c(2:length(colnames(cm3)))]), > : > NA/NaN/Inf in foreign function call (arg 1) > In addition: Warning message: > In storage.mode(x) <- "double" : NAs introduced by coercion > Timing stopped at: 1.33 0.01 1.35 * > > > Thanks in advance, > Mike > > -- > View this message in context: http://r.789695.n4.nabble.com/Random-Forest-Reading-N-A-s-I-don-t-see-them-tp4201546p4201546.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
On Dec 15, 2011, at 2:39 PM, Lost in R wrote:> After checking the original data in Excel for blanks and running > Summary(cm3) > to identify any null values in my data, I'm unable to identify an > instances. > Yet when I attempted to use the data in Random Forest, I get the > following > error. Is there something that Random Forest is reading as null > which is not > actually null? Is there a better way to check for this? > >> library(randomForest) >> system.time( > + rf1 <- randomForest(as.matrix(# Are you aware of the effect of using as.matrix(..) on the storage mode?> cm3[,c(2:length(colnames(cm3)))]),# that was the x argument> + cm3[,1],# The y variable> data=cm3,# That's odd. You already offered the data objects. I wonder what the function will do with that?> ntree=50) > + ) > *Error in randomForest.default(as.matrix(cm3[, > c(2:length(colnames(cm3)))]), > : > NA/NaN/Inf in foreign function call (arg 1) > In addition: Warning message: > In storage.mode(x) <- "double" : NAs introduced by coercionI can see two potential sources of such an error.> Timing stopped at: 1.33 0.01 1.35 * > > > Thanks in advance, > Mike > > -- > View this message in context: http://r.789695.n4.nabble.com/Random-Forest-Reading-N-A-s-I-don-t-see-them-tp4201546p4201546.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.David Winsemius, MD West Hartford, CT