长数字作为字符串 [英] Long Numbers As A Character String

查看:25
本文介绍了长数字作为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为我的数据集的一部分,其中一列是一系列 24 位数字.

As part of my dataset, one of the columns is a series of 24-digit numbers.

例子:

bigonumber <- 429382748394831049284934

当我使用 data.table::freadread.csv 导入它时,它以指数格式显示为数字(例如:4.293827e+23).

When I import it using either data.table::fread or read.csv, it shows up as numeric in exponential format (EG: 4.293827e+23).

options(digits=...) 不起作用,因为数字超过 22 位.

options(digits=...) won't work since the number is longer than 22 digits.

当我这样做时

as.character(bigonumber) 

我得到的是4.29382748394831e+23"

what I get is "4.29382748394831e+23"

有没有办法将 bigonumber 转换为字符串并将所有数字显示为字符?我不需要对其进行任何数学运算,但我确实需要对其进行搜索并对其进行 dplyr 连接.

Is there a way to get bigonumber converted to a character string and show all of the digits as characters? I don't need to do any math on it, but I do need to search against it and do dplyr joins on it.

导入后我需要这样做,因为列号每个月都不同.

I need to this after import, since the column number varies from month to month.

(是的,在完美的世界中,我的上游数据提供者会使用散列而不是长数字和每个月保持不变的静态列数,但我无法向他们规定.)

(Yes, in the perfect world, my upstream data provider would use a hash instead of a long number and a static number of columns that stay the same every month, but I don't get to dictate that to them.)

推荐答案

您可以在 fread 或 read.csv 语句中指定 colClasses.

You can specify colClasses on your fread or read.csv statement.

bignums
429382748394831049284934
429382748394831049284935
429382748394831049284936
429382748394831049284937
429382748394831049284938
429382748394831049284939

bignums <- read.csv("~/Desktop/bignums.txt", sep="", colClasses = 'character')

这篇关于长数字作为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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