• Register
1 vote
1.2k views

Problem :

I am facing following error :

formula(formula, data = data) :

 invalid model formula in ExtractVars

I am using the below code:

install.packages("rpart")

library("rpart")

# you must  change the below from windows to work on your linux box:

mydata <- read.csv(file="c:/Users/md79068/downloads/winequality-red.csv")

# To grow the tree

fit <- rpart(YouSweetMan ~ "residual sugar" + "citric acid", method = "class", data = mydata

Please note that I have changed the delimiters in my CSV file to commas.

I guess it is unable to read the data correctly. I am very new to the R and also a very new programmer.

6 5 3
7,540 points

1 Answer

0 votes

Solution :

Please have a look at the names(mydata). When you tried to create the data.frame, read.table() will turn the "bad" column names into the good column names. You must not have the space in a column name so the R changes spaces to periods. Also, you should never keep the quoted strings in the formula. Please try below approach :

fit <- rpart(quality ~ residual.sugar + citric.acid, method = "class", data = mydata)

I don’t know what the "YouSweetMan" was supposed to do so I just changed it to "quality").

If you follow the above mentioned approach you will get rid of all the issues.

9 7 4
38,600 points

Related questions

0 votes
1 answer 424 views
424 views
Problem : I want to use the neural net for predictions. I am trying to create some X as follows : x <- cbind(seq(1, 50, 1), seq(51, 100, 1)) I am trying to create some Y as follows : y <- x[,1]*x[,2] Give them the names as follows colnames(x) ... =0.01) error in terms.formula(formula) : '.' in formula and no 'data' argument Does anybody have any idea regarding the error I am facing? Any solution?
asked Dec 11, 2019 alecxe 7.5k points
1 vote
1 answer 520 views
520 views
Problem : I am beginner to Scatter Plot. I have recently joined new project and they gave task to plot the simple best fit line to a scatterplot. If I try to execute my below code with my data I always face the following error message: plot(log(datatest$MEAN_intact_for),log( ... plot my graph it works as expected but the problem comes up if I try to add a abline command to have a best fit line.
asked Apr 14 morrisBson 3.2k points
0 votes
2 answers 779 views
779 views
Problem : I am looking for the function with the parameters such as data name as (mydata), factor as (myfactor) and variable names such as (myvar) to dynamically generate the histograms as I have to use them in lattice. I tried to do as mentioned above but error appears ... of type 'character'. I think the program doesn't know where to look for this myf` string. How should I fix this issue?
asked Dec 23, 2019 alecxe 7.5k points
0 votes
1 answer 132 views
132 views
Problem : I want to use the TraMineR's (version 1.8.4) seqdef-funciton to define the sequence object, however I always face the following error message which is completely senseless to me: Error in row.names<-.data.frame(*tmp*, value = value) : invalid 'row. ... tried running it after re-labeling the states without "-", but it does not affect the error. Does someone knows what causes this error?
asked Dec 6, 2019 alecxe 7.5k points