简体   繁体   English

如何读取.csv 列作为逻辑而不是字符?

[英]How to read.csv a column as logical and not as character?

Into a csv file I have a column which contains logical operator values TRUE, FALSE.在 csv 文件中,我有一列包含逻辑运算符值 TRUE、FALSE。

When I use read.csv as following当我使用 read.csv 如下

it reads the column as character.它将列读取为字符。 How can I modify read.csv() to read it as logi?如何修改 read.csv() 以将其读取为 logi?

I use this option of read as I have multiple csv files我使用这个读取选项,因为我有多个 csv 文件

files <- list.files(path = "C/path/files",pattern = ".csv")
temp <- lapply(files, fread, sep=",")
dframe <- rbindlist( temp )

Use the colClasses argument of the read.csv function.使用colClassesread.csv参数。 Provide a character vector of classes for the columns in your data set.为数据集中的列提供类的字符向量。

From the help page of read.csv :read.csv的帮助页面:

colClasses character. colClasses字符。 A vector of classes to be assumed for the columns...为列假定的类向量...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM