You added the `as.factor(dataCancer$Classification)`

in the script, but even if the dataset *dataCancer* is attached, a command like the one above does not transform the dataset variable *Classification* into a factor. It only returns a factor on the console.

Since you want to fit the model on the training dataset, you either specify

training_data$Classification <- as.factor(training_data$Classification) classification_model <- glm(Classification ~ ., data = training_data, family = binomial)

or use the *as.factor* function in the *glm* line code

classification_model <- glm(as.factor(Classification) ~ ., data = training_data, family = binomial)

### Related Posts:

- Error in plot.new() : figure margins too large, Scatter plot
- Reasons for using the set.seed function
- Error: could not find function “%>%”
- R on MacOS Error: vector memory exhausted (limit reached?)
- R programming: How do I get Euler’s number?
- adding x and y axis labels in ggplot2
- Set NA to 0 in R
- R: Using equation with natural logarithm in nls
- Error in do_one(nmeth) : NA/NaN/Inf in foreign function call (arg 1)
- Non-numeric Argument to Binary Operator Error in R
- What are the “standard unambiguous date” formats for string-to-date conversion in R?
- What are the “standard unambiguous date” formats for string-to-date conversion in R?
- R issue “object not found”
- How do I delete rows in a data frame?
- Error in grid.Call(L_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : Polygon edge not found
- Remove duplicated rows
- Error in plot.window(…) : need finite ‘xlim’ values
- R ggplot2 scale_y_continuous : Combining breaks & limits
- Extracting value specific rows in R
- case_when in mutate pipe
- Error in file(file, “rt”) : invalid ‘description’ argument in complete.cases program
- Error in plot.window(…) : need finite ‘xlim’ valuescc
- Longer object length is not a multiple of shorter object length?
- Error: Incorrect number of dimensions in R
- plot.new has not been called yet
- dim(X) must have a positive length when applying function in data frame
- Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, …) : NA/NaN/Inf in ‘y’, tried every possible way
- Persistent invalid graphics state error when using ggplot2
- Error: attempt to use zero-length variable name
- Add text to ggplot
- How to debug “contrasts can be applied only to factors with 2 or more levels” error?
- R error: cannot coerce type ‘closure’ to vector of type ‘double’
- Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, …) : NA/NaN/Inf in ‘y’, tried every possible way
- R t-test Grouping factor must have exactly 2 levels error
- remove legend title in ggplot
- Understanding the order() function
- Subscript out of bounds – general definition and solution?
- Plot a line graph, error in xy.coords(x, y, xlabel, ylabel, log) : ‘x’ and ‘y’ lengths differ
- Sum rows in data.frame or matrix
- Remove grid, background color, and top and right borders from ggplot2
- R: “Unary operator error” from multiline ggplot2 command
- invalid type (list) for variable
- not a Stata version 5-12 .dta file
- How to subset a Data frame column wise using column names?
- Create an empty data.frame
- MLE error in R: initial value in ‘vmmin’ is not finite
- No non-missing arguments warning when using min or max in reshape2
- Custom legend for multiple layer ggplot
- `fread` with headers with special characters (latin1) and unusual nested quotes
- How do you create vectors with specific intervals in R?
- How to move or position a legend in ggplot2
- Singularity in backsolve at level 0, block 1 in LME model
- “installation of package ‘FILE_PATH’ had non-zero exit status” in R
- Nested ifelse statement
- Convert categorical variables to numeric in R
- Plot multiple lines (data series) each with unique color in R
- Plot two graphs in same plot in R
- How to overcome error:”attempt to set ‘colnames’ on an object with less than two dimension” in xts object
- Plot a legend outside of the plotting area in base graphics?
- readOGR() cannot open file
- lme4 error: boundary (singular) fit: see ?isSingular
- R error in unique.default(x) unique() applies only to vectors
- object of type ‘builtin’ is not subsettable
- What causes an R script to get Killed?
- What’s the difference between facet_wrap() and facet_grid() in ggplot2?
- ggplot2, facet_grid, free scales?
- dplyr mutate with conditional values
- Optimization of a function in R ( L-BFGS-B needs finite values of ‘fn’)
- `Error in file(con, “r”) : cannot open the connection` from running BRugsFit()
- Getting invalid model formula in ExtractVars when using rpart function in R
- Error in match.fun(FUN)
- Error in file(filename, “r”, encoding = encoding) : cannot open the connection
- How to solve prcomp.default(): cannot rescale a constant/zero column to unit variance
- How Do You Compare Two Strings in R?
- Argument “No” is missing, with no default
- Creating a Plot Window of a Particular Size
- Error:attempt to apply non-function
- R apply function with multiple parameters
- Error in
: target of assignment expands to non-language object - Error: Invalid number of ‘breaks’ in R
- Efficiently sum across multiple columns in R
- How to eliminate “NA/NaN/Inf in foreign function call (arg 7)” running predict with randomForest
- Sample random rows in dataframe
- Error in eval(predvars, data, env) : object ‘Rm’ not found
- How do I clean up R memory without restarting my PC?
- Deleting rows that are duplicated in one column based on the conditions of another column
- Side-by-side plots with ggplot2
- How to convert data.frame column from Factor to numeric [duplicate]
- non-numeric argument to binary operator
- Column standard deviation R [duplicate]
- why nrow(dataframe) and length(dataframe) in r give different results?
- Meaning of objects being masked by the global environment
- how to add dashed horizontal line with label in ggplot
- Difference between as.POSIXct/as.POSIXlt and strptime for converting character vectors to POSIXct/POSIXlt
- Create a matrix of scatterplots (pairs() equivalent) in ggplot2
- cbind warnings : row names were found from a short variable and have been discarded
- Filter rows which contain a certain string
- How can I change the name of a data frame
- Error in summary.connection(connection) : invalid connection
- In R, dealing with Error: ggplot2 doesn’t know how to deal with data of class numeric