简体   繁体   English

r min函数未返回正确的小数位数

[英]r min function does not return the correct number of decimals

In RI am using the min function on a vector of numeric values, like this vector: 在RI中,我在数值向量上使用min函数,例如以下向量:

v <- c(16.22900, 16.28857, 16.47363, 16.47412, 16.00000, 16.49463, 16.27246, 16.0366, 16.49609)

However when I apply the min function, I get this return value 但是,当我应用min函数时,我得到了这个返回值

min(v)
[1] 16

instead I would like this result: 相反,我想要这个结果:

[1] 16.00000

I checked the class of the vector but all seems ok 我检查了向量的类别,但一切似乎都还好

class(v)
[1] "numeric"

Where is the problem? 问题出在哪儿?

You are caught between internal representation of a value and how it is displayed . 您会陷入一个值的内部表示及其 显示方式之间

R> v <- c(16.22900, 16.28857, 16.47363, 16.47412, 16.00000, 
+         16.49463, 16.27246, 16.0366, 16.49609)
R> min(v)
[1] 16
R> sprintf("%10.8f", min(v))
[1] "16.00000000"
R> identical(min(v), 16.0000000000000000000)
[1] TRUE
R>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM