本文介绍了data.table :: fread一种`integer64`类型,仅手动覆盖colClass一列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个.csv,其中一列ID包含一个带前导零的长整数。 fread 将其转换为 integer64 类型。我将如何为一列指定类,然后让 fread 自动猜测其余列的类?不知道这是否是一种全有或全无的情况。

I have a .csv where a column of IDs contains a long integer with leading zeros. fread converts it into an integer64 type. How would I specify the class for one column and then just let fread automatically guess the classes for the remaining columns? Not sure if this is an "all-or-nothing" type of situation.

我有50多个列,宁愿不必为所有类型指定数据类型他们只是因为我必须对其中一个这样做。

I have 50+ columns and would rather not have to specify the data types for all of them just because I have to do so for one of them.

我的问题与以下问题有关:。

My question is related to: R fread - read all columns as character.

推荐答案

读取

# colClasses
data = "A,B,C,D\n1,3,5,7\n2,4,6,8\n"
fread(data, colClasses=c(B="character",C="character",D="character"))  # as read.csv
fread(data, colClasses=list(character=c("B","C","D")))    # saves typing
fread(data, colClasses=list(character=2:4))     # same using column numbers

也就是说,如果您将零填充的列称为 big_num ,则只需使用 colClasses = list(character ='big_num')

That is, if your zero-padded column is called big_num, just use colClasses = list(character = 'big_num')

这篇关于data.table :: fread一种`integer64`类型,仅手动覆盖colClass一列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 09:48