读取CSV文件时出错

时间:2018-03-22 17:09:14

标签: r

使用colclasses参数单独声明变量类型

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 in methods::as(data[[i]], colClasses[i]) : 
  no method or default for coercing “character” to “Numeric”

1 个答案:

答案 0 :(得分:2)

在varTypes中尝试使用小写“n”的numeric(对于因子和字符,同样适用于此)