双精度数据类型和数字数据类型之间的区别 [英] Difference between double- precision data type and numeric data type

查看:292
本文介绍了双精度数据类型和数字数据类型之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在R编程中,双精度数据类型和数字数据类型之间的显着区别是什么?

What is the significant difference between double-precision data type and numeric data type in R programming?

推荐答案

来自

R是一个历史异常,R的浮点向量有两个名称,即double和numeric(以前是实数). double是类型的名称. numeric是模式的名称,也是隐式类的名称.作为S4正式类,请使用数字". 潜在的混淆是R使用模式数字"来表示双精度或整数"

It is a historical anomaly that R has two names for its floating-point vectors, double and numeric (and formerly had real). double is the name of the type. numeric is the name of the mode and also of the implicit class. As an S4 formal class, use "numeric". The potential confusion is that R has used mode "numeric" to mean ‘double or integer’

我们可以认为双精度数属于数字.要看到这个:

We can think of doubles as belonging to numeric. To see this:

 > is.double(1)
 [1] TRUE
 > is.numeric(1)
 [1] TRUE

R通常将数字存储为双精度.使用"numeric()"与"double()"相同.您也可以将数字存储为单个或整数.两者都是数字.出于性能原因,您可以选择强制将一个数字存储为整数,但是除非您要构建一个程序包,否则可能不值得花时间进行权衡.

R normally stores numbers as doubles. Using "numeric()" is the same as "double()." You can also store a number as a single or an integer. Both will be numeric. You may choose to force a number be stored as an integer for performance reasons, but unless you are building a package the trade offs might not be worth your time.

我建议阅读 Gillespie的概述,以获取有关类型的更多信息和性能.

I suggest reading Gillespie's Overview for more info on type and performance.

这篇关于双精度数据类型和数字数据类型之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆