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

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

问题描述

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



示例:

  bigonumber<  -  429382748394831049284934 

它使用 data.table :: fread read.csv ,它以指数格式显示为数字:4.293827e + 23)。



options(digits = ...)

  as。

字符(bigonumber)

我得到的是4.29382748394831e + 23



有没有办法得到 bigonumber 转换为字符串并显示所有的数字作为字符?我不需要做任何数学,但我需要搜索它,并 dplyr 加入它。



我需要在导入后输入,因为列号每月都有所不同。



在完美的世界中,我的上游数据提供程序将使用哈希,而不是长数和每月保持不变的静态列数,但我不能指定给他们。)

解决方案

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

  bignums 
429382748394831049284934
429382748394831049284935
429382748394831049284936
429382748394831049284937
429382748394831049284938
429382748394831049284939

bignums< .csv(〜/ Desktop / bignums.txt,sep =,colClasses ='character')


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

Example:

bigonumber <- 429382748394831049284934

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=...) won't work since the number is longer than 22 digits.

When I do

as.character(bigonumber) 

what I get is "4.29382748394831e+23"

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.)

解决方案

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天全站免登陆