• Register
1 vote

Problem :

I am facing following error :

formula(formula, data = data) :

 invalid model formula in ExtractVars

I am using the below code:



# 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

Please log in or register to answer this question.

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 727 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 1.1K 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, 2020 morrisBson 3.2k points
0 votes
2 answers 1.2K 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 219 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
0 votes
1 answer 306 views
0 votes
1 answer 464 views
0 votes
1 answer 575 views
Problem: I have descent knowledge in R and plot. I have gained this knowledge by attending the online tutorials. Now I have the very simple and only single data file test.txt which contains the data as shown below for your reference: 1  5  7  9  11 Now I am ... : invalid plotting method. Can some expert point out what I am doing wrong here or try to suggest the better solution for above error?
asked Jul 27, 2020 Raphael Pacheco 4.9k points
1 vote
1 answer 1.4K views
Problem : I want to use the glmnet package on a dataset. I am trying to use cv.glmnet() to get the lambda value for the glmnet(). Please find below the dataset and error message: > head(t2) X1 X2 X3 X4 X5 X6 X7 X8 X9 X10 X11 X12 1 ... in evaluating the argument 'x' in selecting a method for function 't': Error: invalid class 'NA' to dup_mMatrix_as_dgeMatrix Any suggestions regarding the solution?
asked Dec 14, 2019 alecxe 7.5k points
0 votes
1 answer 1.4K views
Problem : I think my dataframe is correct and my code is also okay. But I am facing following error: Error in .Call.graphics(C_palette2, .Call(C_palette2, NULL)) : invalid graphics state What is wrong with my below data? date trt var val 1/12/2019 cc sw5 0.2684138 1/12/2019 ... ] Also I want to make the scatterplot as follows: ggplot(data = df,aes(x = date,y = val)) + geom_point(aes(group = trt))
asked Dec 6, 2019 alecxe 7.5k points
0 votes
2 answers 974 views
Problem : How to solve the below error, I will first show an example of the data file. My Data file: col1  col2    col3 1     2       3 1     2       3 5     6       7 My R code: read.table("mydemo.txt", header = TRUE, sep = "\t", row.names = "a") My Output ... In read.table(file = file, header = header, sep = sep, quote = quote,  : incomplete final line found by readTableHeader on '../mydemo.txt'
asked Jan 17, 2020 jwilliam 3.9k points