R 中的单位转换
我想在 R 中将英制单位转换为公制单位,反之亦然。我该怎么做?
如果当前没有方法可以做到这一点,我怎样才能创建一个包呢?
I would like to convert from imperial units to metric and vice versa in R. How do I go about doing that?
If there is no current way of doing that, how can I create a package that would?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
编辑:现在有一个百科全书式的单位包: NISTunits
单位的性质可能会影响存在或不存在。不幸的是,总的来说,我认为@gsk3是正确的。 'Hmisc'、'gdata' 和 'marelac' 包中有一些功能:
设置单位属性(不仅仅是时间对象):
http://finzi.psych.upenn.edu/R/ Library/Hmisc/html/units.html
医疗:
http://finzi.psych.upenn.edu/R/ Library/gdata/html/ConvertMedUnits.html
'marelac' 索引(主要针对海洋学)
http://finzi.psych.upenn.edu/R/ Library/marelac/html/00Index.html
温度:
http://finzi.psych.upenn.edu/R/ Library/marelac/html/convert_T.html
气压:
http://finzi.psych.upenn.edu/R/ Library/marelac/html/convert_p.html
@Brian Diggs 在回答类似问题时提到了包“dielectric”:
链接到包“dielectric”中的“constants”帮助页面
我认为这些将提供这样做的示例,并且函数
package.sculpture
应该有助于包创建的机制。我认为这个包将是一个受欢迎的补充。更新:Gabor Grothendieck 在 2012 年 7 月 23 日向 rhelp 提出的类似问题中提到了“udunits2”软件包。它似乎需要安装同名的独立操作系统特定软件包。如果没有这样的安装,您会收到一条相当无用的错误消息:
Edit: There is now an encyclopedic units package: NISTunits
The nature of the units may affect the presence or absence. In general I think, unfortunately, that @gsk3 is correct. There are some function in the 'Hmisc', 'gdata', and 'marelac' packages:
Setting a units attribute (for more than just time objects):
http://finzi.psych.upenn.edu/R/library/Hmisc/html/units.html
Medical:
http://finzi.psych.upenn.edu/R/library/gdata/html/ConvertMedUnits.html
'marelac' Index (mostly specialized to oceanography)
http://finzi.psych.upenn.edu/R/library/marelac/html/00Index.html
Temperature:
http://finzi.psych.upenn.edu/R/library/marelac/html/convert_T.html
Barometric:
http://finzi.psych.upenn.edu/R/library/marelac/html/convert_p.html
Package "dielectric" was mentioned by @Brian Diggs in an answer to a similar question:
Link to 'constants' help page in package 'dielectric'
I think those will provide examples of doing so and the function
package.skeleton
should help with the mechanics of package creation. I think the package would be a welcome addition.Update: The 'udunits2' package was mentioned by Gabor Grothendieck in a similar question to rhelp July 23, 2012. It appears to require installation of a stand-alone OS-specific package of the same name. Without such installation you get a rather unhelpful error message:
我知道这已经很晚了,但是
measurements
包有一个conv_unit()
函数,它可能就是您正在寻找的。您输入您拥有的英制值、要转换的单位(例如“ft”)以及要转换为的单位(例如“km”)。它有多种不同的尺寸(不仅仅是长度)。I know this is very late, but the package
measurements
has a functionconv_unit()
that may be what you're looking for. You enter the imperial value you have, what unit you're converting from (e.g. 'ft') and what you want to convert to (e.g. 'km'). It has a variety of different dimensions (not just length).今天有一个名为 units 的“新”R 软件包,它是基于不久前发布的 udunits2 R 软件包构建的。
查看:https: //cran.r-project.org/web/packages/units/vignettes/units.html#setting-units-unit-conversion
There is a "new" R package called units today, that was built upon the udunits2 R package, which is available a while ago.
Have a look to: https://cran.r-project.org/web/packages/units/vignettes/units.html#setting-units-unit-conversion
grid 包中有
unit()
和convertUnit()
函数用于指定不同的长度和尺寸单位。这可能会满足您的要求,或者如果没有的话,也可以为您提供一个起点。There is the
unit()
andconvertUnit()
functions in the grid package for specifying different length and dimension units. That may do what you want, or give you a place to start if not.udunits2
包就是这样做的。它包含强大的 UDUNITS 库:最重要的是,
units
包(正在进行中)旨在提供一个类型安全的系统带单位的算术:The
udunits2
package does just that. It wraps the powerful UDUNITS library:On top of that, the
units
package (work in progress) aims at providing a type-safe system for doing arithmetics with units: