我正在尝试在 R 中的 read.csv
函数中指定 colClasses
选项。在我的数据中,第一列 time
是基本上是一个字符向量,而其余的列是数字。
data <- read.csv("test.csv", comment.char="" ,
colClasses=c(time="character", "numeric"),
strip.white=FALSE)
在上面的命令中,我希望 R 在 time
列中读取“字符”,其余部分读取为数字。尽管在命令完成后,data
变量确实得到了正确的结果,但 R 返回了以下警告。我想知道如何修复这些警告?
Warning messages:
1: In read.table(file = file, header = header, sep = sep, quote = quote, : not all columns named in 'colClasses' exist
2: In tmp[i[i > 0L]] <- colClasses : number of items to replace is not a multiple of replacement length
德里克
最佳答案
您只能为一列指定 colClasse。
所以在你的例子中你应该使用:
data <- read.csv('test.csv', colClasses=c("time"="character"))
关于r - 在 read.csv 中指定 colClasses,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2805357/