Skip to content
Prev 221423 / 398500 Next

Regarding the 'R' Load Command

Hi Steve, Gavin

This is being really helpful. I've pasted the working data, and my test
data below after running the str command on both of those variables. The
working sample actually contains about 300 records, hence I am not able
to paste the whole data here. However my sample test data which I am
trying to get working, is only 1 record, and I've pasted the dput result
below. Datatypes  seem to match in both variables for me in terms of
being num/factor. Please suggest where it could be wrong. Thank You!



mytestdata

structure(list(imurder = 0, itheft = 0, irobbery = 0, iassault = 1L,
idrug = 0L, iburglary = 0L, igun = 0L, psych = 0L, Freq = 0L,     priors
= 58L, firstage = 19L, intage = 19L, sex = structure(1L, .Label = "1",
class = "factor"), race = structure(1L, .Label = "BLACK", class =
"factor"),     marstat = structure(1L, .Label = "SINGLE", class =
"factor"),     empac = structure(1L, .Label = "UNEMPLD", class =
"factor"),     educ = 0L, zipcode = 21215L, suspendmn = 0L, drugs = 0L,
alco = 0L, probation = 1L, parole = 0L), .Names = c("imurder", "itheft",
"irobbery", "iassault", "idrug", "iburglary", "igun", "psych", "Freq",
"priors", "firstage", "intage", "sex", "race", "marstat", "empac",
"educ", "zipcode", "suspendmn", "drugs", "alco", "probation", "parole"),
class = "data.frame", row.names = "10")
'data.frame':   291 obs. of  23 variables:
 $ imurder  : num  0 0 0 0 0 0 0 0 0 0 ...
 $ itheft   : num  0 0 0 0 0 1 0 0 0 0 ...
 $ irobbery : num  0 0 0 0 0 0 0 0 0 0 ...
 $ iassault : num  1 0 1 0 0 0 0 0 0 0 ...
 $ idrug    : num  0 1 0 1 1 0 0 1 1 1 ...
 $ iburglary: num  0 0 0 0 0 0 0 0 0 0 ...
 $ igun     : num  0 0 0 0 0 0 0 0 0 0 ...
 $ psych    : num  0 0 0 0 0 0 0 0 0 0 ...
 $ Freq     : num  0 0 0 0 0 0 0 0 0 0 ...
 $ priors   : num  58 4 2 0 6 22 0 36 0 0 ...
 $ firstage : num  19 39 28 0 49 32 0 24 0 55 ...
 $ intage   : num  19 39 28 25 49 32 32 24 30 55 ...
 $ sex      : Factor w/ 2 levels "1","2": 1 2 1 2 2 1 1 1 1 1 ...
 $ race     : Factor w/ 5 levels "WHITE","BLACK",..: 2 2 1 1 2 1 1 2 2 2
...
 $ marstat  : Factor w/ 7 levels "SINGLE","MARRIED",..: 1 2 2 1 2 4 7 1
7 3 ...
 $ empac    : Factor w/ 6 levels "EMPLD FT","EMPLD PT",..: 3 4 3 3 3 3 6
3 6 3 ...
 $ educ     : num  0 0 0 1 0 0 0 0 0 1 ...
 $ zipcode  : num  21215 21217 21223 21223 21217 ...
 $ suspendmn: num  0 600 0 0 60 3 2 479 0 3 ...
 $ drugs    : num  0 1 0 0 0 1 0 0 0 1 ...
 $ alco     : num  0 0 0 0 0 1 0 0 0 1 ...
 $ probation: num  1 1 0 0 1 1 1 1 0 1 ...
 $ parole   : num  0 0 0 0 0 0 0 0 0 0 ...
'data.frame':   1 obs. of  23 variables:
 $ imurder  : num 0
 $ itheft   : num 0
 $ irobbery : num 0
 $ iassault : num 1
 $ idrug    : num 0
 $ iburglary: num 0
 $ igun     : num 0
 $ psych    : num 0
 $ Freq     : num 0
 $ priors   : num 58
 $ firstage : num 19
 $ intage   : num 19
 $ sex      : Factor w/ 1 level "1": 1
 $ race     : Factor w/ 1 level "BLACK": 1
 $ marstat  : Factor w/ 1 level "SINGLE": 1
 $ empac    : Factor w/ 1 level "UNEMPLD": 1
 $ educ     : num 0
 $ zipcode  : num 21215
 $ suspendmn: num 0
 $ drugs    : num 0
 $ alco     : num 0
 $ probation: num 1
 $ parole   : num 0
Best Regards,

Murali Godavarthi

410-585-3746 (w)

ITCD - DPSCS Data Mining


-----Original Message-----
From: Gavin Simpson [mailto:gavin.simpson at ucl.ac.uk] 
Sent: Wednesday, May 19, 2010 12:58 PM
To: Steve Lianoglou
Cc: Godavarthi, Murali; r-help at r-project.org
Subject: Re: [R] Regarding the 'R' Load Command

I think the answer is clear from the error: R thinks the type of data in
the components of 'testmurali' do not match those of the data used to
fit the original randomForest.

The OP should go back to his model fitting code and do

str(obj)

where 'obj' is the name of his original data object used to fit the
randomForest and compare it with

str(testmurali)

to see why the types of data are different. Look for variables that were
factors or characters in one data set and numeric/integer in the other.
This smells like a data import issue...

If revelation still doesn't occur Murali, *please* follow Steve's
suggestions and post and message that shows exactly (i.e. the R code
executed) along side a data set *we* can load into R without jumping
through hoops or having to divine what your data look like using a
crystal ball or ESP.

HTH

G
On Wed, 2010-05-19 at 12:24 -0400, Steve Lianoglou wrote:
your
predict
function to
is 0
"parole"
21215 0
of
above.
"empac"
data.
on a
string)?
responses
is
program
the
connections
the
the
is
function
please!
load
think
can
because
which