在read.csv中指定colClasses [英] Specifying colClasses in the read.csv

查看:1134
本文介绍了在read.csv中指定colClasses的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在R中的 read.csv 函数中指定 colClasses 选项。第一列时间基本上是字符向量,而其余列是数字。

  data < csv(test.csv,comment.char =,
colClasses = c(time =character,numeric),
strip.white = FALSE)

在上面的命令中,我希望R在time列中读取为character,其余为数字。虽然,数据变量在命令完成后具有正确的结果,R返回以下警告。我想知道如何可以解决这些警告?

 警告消息:
1:在read.table(file = file,header =不是所有在'colClasses'中命名的列都存在
2:在tmp [i [i> 0L]]中< - colClasses:
number要替换的项目不是替换长度的倍数

Derek

rest 为5:

colClasses向量的长度必须等于导入列的数量。

  colClasses = c(character,rep(numeric,5))
pre>

I am trying to specify the colClasses options in the read.csv function in R. In my data, the first column "time" is basically a character vector while the rest of the columns are numeric.

data <- read.csv("test.csv", comment.char="" , 
                 colClasses=c(time="character", "numeric"), 
                 strip.white=FALSE)

In the above command, I would want R to read in the "time" column as "character" and the rest as numeric. Although, the "data" variable did have the correct result after the command completed, R returned the following warnings. I am wondering how I could fix these warnings?

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

Derek

解决方案

The colClasses vector must have length equal to the number of imported columns. Supposing the rest of your dataset columns are 5:

colClasses=c("character",rep("numeric",5))

这篇关于在read.csv中指定colClasses的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆