Re: [问题] 型态转换 文字转数字 最大位数

楼主: Edster (Edster)   2016-08-23 00:25:52
※ 引述《f496328mm (为什么会流泪)》之铭言:
: y= c("195875715247033841" )
: as.numeric( y )
: # 195875715247033856
: 因为一些原因
: 会用到位数非常大的data
: 像上面y这样 我想要把他转成数字 做排序之类
: 就会转失败 没有办法完全文字转数字
: 虽然R一样会转成一组数字 但不是我要的
: 因为我还会再把他转回文字
: 这样一来一往 资料就会改变
: 想问问看有没有什么解决方法
: options(digits=22)
: 我也有开到最大位数
: 可是依然不行
: 谢谢
library(magrittr)
library(bit64)
# library(forRest)
y1= c("195875715247033841")
y2= c("195875715247033842")
y3= c("195875715247033839")
y=c(y1,y2,y3)
substring(y, c(4,6,8,10,12), c(6,8,10,12,30))
t1 = Sys.time()
sortedData =lapply(y, function(x)substring(x, c(4,6,8,10,12),
c(6,8,10,12,30))) %>% do.call(rbind,.) %>% sortbyrowR(., decreasing=FALSE)
apply(sortedData,1,function(x) paste(x,collapse = ""))
t2=Sys.time()
t2-t1
Time difference of 0.012008905410766602 secs
t1=Sys.time()
as.integer64(y) %>% sort
t2=Sys.time()
t2-t1
Time difference of 0.006504058837890625 secs
sortbyrowR 是参照C版大的文章, http://pastebin.com/zE0bQT3U
作者: f496328mm (为什么会流泪)   2016-08-23 00:30:00
谢谢 用as.integer64 就能完美转换成功
楼主: Edster (Edster)   2016-08-23 00:39:00
没关系,总有机会用到。

Links booklink

Contact Us: admin [ a t ] ucptt.com