Decision Tree Error Message

291 views
Skip to first unread message

Saman Khaje-Zade

unread,
May 31, 2015, 5:29:02 AM5/31/15
to rattle...@googlegroups.com
Hello all,

I am following a book to learn Data Mining in R and have got stuck at this stage

I ran the following code in R Console to build a decision tree model:

library(rpart)

weatherDS <- new.env()

library(rattle)

evalq({
data <- weather
nobs <- nrow(data)
vars <- -grep('^(Date|Locat|RISK) ', names(weather))
}, weatherDS)

evalq({
set.seed(42)
train <- sample(nobs, 0.7*nobs)
}, weatherDS)

evalq({
form <- formula(RainTomorrow ~ .)
}, weatherDS)

weatherRPART <- new.env(parent=weatherDS)

evalq({
model <- rpart(formula=form, data=data[train, vars])
}, weatherRPART)

And got the following message:

Error in terms.formula(formula, data = data) : 
  '.' in formula and no 'data' argument

Any help would be appreciated

All the best,
Saman

Graham Williams

unread,
May 31, 2015, 7:02:33 AM5/31/15
to rattle-users
Hi Saman,

In the line


vars <- -grep('^(Date|Locat|RISK) ', names(weather))

there is an extra space before the second quote. This results in the variable vars being empty. It should be:


vars <- -grep('^(Date|Locat|RISK)', names(weather))

Regards,
Graham Williams

--
You received this message because you are subscribed to the Google Groups "rattle-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rattle-users...@googlegroups.com.
To post to this group, send email to rattle...@googlegroups.com.
Visit this group at http://groups.google.com/group/rattle-users.
For more options, visit https://groups.google.com/d/optout.

Saman Khaje-Zade

unread,
May 31, 2015, 11:40:47 PM5/31/15
to rattle...@googlegroups.com
Hi Graham,

I removed the space, and it worked
Thank you for your time and your help

All the best,
Saman
Reply all
Reply to author
Forward
0 new messages