[英]R is turning large numbers to negative random numbers
I am having an issue when importing into R multiple data structures saved as *.mat files by using readMat(). 使用readMat()将多个保存为* .mat文件的数据结构导入R时遇到问题。
When I read and open the file in R, the content of one single column stored in the data structure changes (apparently) randomly (should be 1504615865460506 and is -1372641510 for example). 当我在R中读取并打开文件时,存储在数据结构中的单个列的内容(显然)是随机变化的(例如,应为1504615865460506,并且为-1372641510)。 Also, numbers in the original *.mat file are increasing (1st is 1484649519139343, 2nd is 1484649519142687 etc), while in R corresponding numbers are decreasing (1st is -1372641510, 2nd is -1372633137 etc).
此外,原始* .mat文件中的数字正在增加(第一个是1484649519139343,第二个是1484649519142687等),而在R中,相应的数字正在减少(第一个是-1372641510,第二个是-1372633137等)。 No change is occurring on the other variables.
其他变量没有变化。
The "wronged" variable is the TimeStamp, a progressive number indicating the exact time a data point was recorded. “错误”变量是TimeStamp,它是一个渐进数字,指示记录数据点的确切时间。 It is stored into a column, part of a list, part of a even bigger list.
它存储在一列,列表的一部分,甚至更大的列表的一部分中。 It is 'integer' according to class().
根据class(),它是“整数”。 I read readMat() documentation, though I did not find anything related.
尽管没有发现任何相关内容,但我阅读了readMat()文档。 In case the problem was the large number, I set options(digits=20), with no effect.
万一问题是大数目,我设置选项(数字= 20),不起作用。
Any ideas/suggestions will be greatly appreciated! 任何想法/建议将不胜感激!
And I attach my code. 然后附上我的代码。
library(R.matlab)
setwd("C:/Path")
options(digits=20)
temp = list.files(pattern="*.mat")
list2env(lapply(setNames(temp, make.names(gsub("*.mat$", "", temp))), readMat), envir = .GlobalEnv)
rm(temp)
listAll<-list(mget(ls())) #listAll contains all the *.mat files.
listAll[[1]][[3]] #listAll contains N lists == N of *.mat files.
This is an example of the structure of the 3rd list: 这是第三个列表的结构示例:
# $data
# , , 1
#
# [,1]
# ID "A6001"
# TimePoint "10"
# MainBuffer List,12
# TimeBuffer List,12 #TimeBuffer is the Time Stamp.
TimeBuffer contains 12 lists, corresponding to 12 trials. TimeBuffer包含12个列表,对应于12个试验。 Each trial has 1 column, which is the one that is unwillingly changed in the process.
每个试验都有1列,这是在此过程中不希望更改的列。
# EventBuffer List,12
# Log List,12
#
#
# attr(,"header")
# attr(,"header")$description
# [1] "MATLAB 5.0 MAT-file, Platform: MACI64, Created on: Wed Sep 20 16:03:45 2017 "
#
# attr(,"header")$version
# [1] "5"
#
# attr(,"header")$endian
# [1] "little"
listAll[[1]][[3]][[1]][[4]][[3]][[1]][1,][1]
#[1] 668725504 (and should be 1480500650907453)
should be 1504615865460506 and is -1372641510 for example
应该是1504615865460506,例如是-1372641510
Looks like an overflow error. 看起来像是一个溢出错误。
From help(integer)
in R: 从R中的
help(integer)
:
Note that current implementations of R use 32-bit integers for integer vectors, so the range of representable integers is restricted to about +/-2*10^9: 'double's can hold much larger integers exactly.
请注意,R的当前实现将32位整数用于整数矢量,因此可表示整数的范围被限制为大约+/- 2 * 10 ^ 9:“ double”可以精确地容纳更大的整数。
So, you'll need to use a larger type such as double
for the values in question. 因此,您需要为所涉及的值使用更大的类型,例如
double
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.