I found multiple post on internet however, I'm still not able to remplace the "?" value by "-1" as asked by my teacher. This is my code:
>library(e1071);
>mammogram <- data.frame
>mammogram.frame = read.table("https://archive.ics.uci.edu/ml/machine-learning-databases/mammographic-masses/mammographic_masses.data",
sep=",",
col.names=c("Birads","Age","Shape","Margin","Density","Severity"),
fill=TRUE,
strip.white=TRUE)
>mammogram.frame[which(mammogram.frame=="?")]<-"-1"
>mammogram.frame
>summary(mammogram.frame)
>svm.model <- svm(Density~.,
data=mammogram.frame,
type="C-classification",
cost=1.0,
kernel="polynomial",
degree=2.0)
>svm.model
and when I run the code, the mammogram.frame[which(mammogram.frame=="?")]<-"-1"
return the following output:
> mammogram.frame[which(mammogram.frame=="?")]<-"-1"
Error in `[<-.data.frame`(`*tmp*`, which(mammogram.frame == "?"), value = "-1") :
new columns would leave holes after existing columns
I also tried the code below but it transform my data in something else...
> mammogram.frame <- as.character(mammogram.frame)
> mammogram.frame[mammogram.frame == "?"] <- "-1"
> mammogram.frame
[1] "c(6, 5, 6, 5, 6, 5, 5, ...)
> mammogram.frame <- as.factor(mammogram.frame)
> mammogram.frame
[1] c(6, 5, 6, 5, 6, 5, 5, ...)
I mean by that that it doesn't give my the same visual as the beginning when I run >mammogram.frame
..
Any idea to passe the "?" value to -1? because it works when I do >mammogram.frame[which(mammogram.frame=="?")] <- NA
Thank !