read.csv 没有截断或舍入,但您的print.data.frame 函数仅显示options() 中指定的精度值。试试:
print(dfrm, digits=10)
> dfrm<- data.frame(test=-117.2403266)
> print(dfrm)
test
1 -117.2403
> print(dfrm, digits=10)
test
1 -117.2403266
按照建议使用format 将表明精度没有丢失,但它会返回一个字符向量,因此它可能不适合在需要数值时进行赋值。
编辑 2 年前的帖子:这个主题可能会提出一个问题,即当整数大于 .Machine$integer.max #[1] 2147483647 时如何导入整数,因为它们现在可以在内部完全存储为“数字”横坐标值,因此最大值为 2^52(或 2^53-1,我忘记了)。当这些是从基于scan 的函数中读取的(read.*-family 中的所有值都是 0f)时,您需要声明为“数字”而不是“整数”:
> str( scan(text="21474836470", what=integer()))
Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, :
scan() expected 'an integer', got '21474836470'
> str( scan(text="21474836470", what=numeric()))
Read 1 item
num 2.15e+10
> str( read.table(text="21474836470", colClasses="integer"))
Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, :
scan() expected 'an integer', got '21474836470'
> str( read.table(text="21474836470", colClasses="numeric"))
'data.frame': 1 obs. of 1 variable:
$ V1: num 2.15e+10
如果您没有为“what”指定类型或模式,scan 将假定 numeric() 并且它会成功。