rlatticenas

R NAs introduced by coercion in string data frame problem


I'm trying to run the following code:

marka <-c("Skoda","Skoda","Opel","Volkswagen","Toyota","Toyota","Ford","Dacia","Skoda","Volkswagen","Nissan","Renault","Hyundai","Fiat","Skoda","Toyota","Toyota","Volkswagen","Dacia","Opel","Kia","SEAT","Kia","Renault","Volkswagen","Toyota","Ford","Hyundai","Volvo","Toyota")
model <- c("Octavia","Fabia","Astra","Golf","Yaris","Auris","Focus","Duster","Rapid","Passat","Qashqai","Clio","Tucson","Tipo","Superb","Corolla","C-HR","Tiguan","Sandero","Corsa","Sportage","Leon","Ceed","Megane","Polo","RAV4","Fiesta","i20","XC60","Aygo")
dfall <- data.frame(marka,model)
xyplot(model~marka,data=dfall)

to make sth like this: enter image description here

But I'm facing such error:

Warning messages:
1: In order(as.numeric(x)) : NAs introduced by coercion
2: In diff(as.numeric(x[ord])) : NAs introduced by coercion
3: In diff(as.numeric(y[ord])) : NAs introduced by coercion
4: In (function (x, y, type = "p", groups = NULL, pch = if (is.null(groups)) plot.symbol$pch else superpose.symbol$pch,  :
  NAs introduced by coercion
5: In (function (x, y, type = "p", groups = NULL, pch = if (is.null(groups)) plot.symbol$pch else superpose.symbol$pch,  :
  NAs introduced by coercion

How can I get rid of this?


Solution

  • For others who would encounter the same problem:

    as Ben explained in the comment, it was enough to set the parameter stringsAsFactors as TRUE, so that the vectors were factors.

    dfall <- data.frame(marka,model, stringsAsFactors = TRUE)