samjigsaw412
samjigsaw412

Reputation: 11

Error while reading a CSV file

Declaring variable types separately using colclasses parameters

varTypes <- c(
  Sepal.Length = 'Numeric', 
  Sepal.Width = 'Numeric', 
  Petal.Length = 'Numeric', 
  Petal.Width = 'Numeric', 
  Species = "Factor", 
  Name = "Character"
)


Flowers <- read.table(
  "C:/Study/JIGSAW/irisone.csv", 
  header=FALSE, 
  sep=",", 
  skip = 1, 
  col.names=names(varTypes), 
  colClasses = varTypes
)

Error message is displayed below:

Error in methods::as(data[[i]], colClasses[i]) : 
  no method or default for coercing “character” to “Numeric”

Upvotes: 1

Views: 617

Answers (1)

iod
iod

Reputation: 7592

Try numeric with a lower case "n" in varTypes (same for Factor and Character, while you're at it)

Upvotes: 2

Related Questions