R 中的物理常数
只是好奇 - 是否有某个包或数据集包含物理常数的值?我之所以这么问,是因为我现在已经多次错误地输入了 273.15
(摄氏度到开尔文转换)。 =)
Just curious - is there a package or dataset somewhere containing values for physical constants? I only ask because I've now typed in 273.15
(Celsius to Kelvin conversion) wrong several times. =)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
收集这些信息是一项相当大的任务,但一些热力学常数在 marelac 中可用:
除了 我对 @joran 引用的问题的回答这些是 NIST 的进一步资源:
http://www.nist.gov/pml/wmd/metric/si- units.cfm
http://www.nist.gov/pml/wmd/pubs/upload/AppC-11-hb44-final.pdf
http://www.nist.gov/pml/wmd/pubs/upload/AppC-11-hb44-final.pdf
我承担了阅读 NIST 常量表的任务,对其进行编辑,以便转换为数字是合理的,这是输入代码:
....这是 dput 版本:
It's a fairly large task to assemble this information but some of the thermodynamic constants are available in marelac:
In addition to the R resources in my answer to the question that that @joran cited these are further resources at NIST:
http://www.nist.gov/pml/wmd/metric/si-units.cfm
http://www.nist.gov/pml/wmd/pubs/upload/AppC-11-hb44-final.pdf
http://www.nist.gov/pml/wmd/pubs/upload/AppC-11-hb44-final.pdf
I took on the task of reading the NIST Constants Table, editing it so the conversion to numeric would be reasonable, and this was the input code:
.... and here is the dput version:
marelac
和dielectric
封装都有一些物理常数,但不是特别的物理常数。marelac::convert_T
将进行温度转换。The packages
marelac
anddielectric
both have some physical constants, but not that one in particular.marelac::convert_T
will do the temperature conversions.我可以推荐 2 个选项:
1)如果您一直需要这些常量,您可以使用
C2K<-273.15
形式的 .First 库。您可以分配常量并将它们存储在那里。有关详细信息,请参阅 http://cran.r-project。 org/doc/contrib/Lemon-kickstart/kr_first.html2) 如果您只想有时使用这些文件,请以与上述相同的格式将常量保存在文本文件中
x<-273.15
然后使用以下格式的 source 函数获取此文件的路径:source(C:\Users\PAth to save file text\formulas.txt)
与依赖可能包含也可能不包含所需内容的包相比,这使您可以更好地控制常量。
May I recommend 2 options:
1) If you need these constants all the time you could make use of the .First library in the form of
C2K<-273.15
. You can assign constants and store them there. For more on this see http://cran.r-project.org/doc/contrib/Lemon-kickstart/kr_first.html2) If you want to use the files only sometimes save the constants in a text file in the same format as above
x<-273.15
and then source the path to this file using the source function in the following format:source(C:\Users\PAth to save file text\formulas.txt)
This gives you more control over the constants than relying on a package that may or may not contain what you want.
下载和解析应该相当容易:
http://physicals.nist.gov /cuu/Constants/Table/allascii.txt
[实际上,该文件的格式不好,并且几个常量甚至破坏了近似的固定宽度格式。需要更聪明的处理才能有用]
Should be fairly easy to download and parse this:
http://physics.nist.gov/cuu/Constants/Table/allascii.txt
[actually scratch that, that file is not nicely formatted, and a couple of the constants break even the approximate fixed-width formatting. Needs cleverer processing to be useful]
这是对 NIST CODATA 物理常数表的另一种解析。它与上面 BondedDust 的答案类似,但由于使用了 stringr(我认为),可读性稍微容易一些。
就是这样。现在,可以轻松地在 R 中搜索数据以查找所需的常量,并将要使用的常量分配给变量名称,而无需手动键入它们。
Here is another parsing of the NIST CODATA table of physical constants. It is similar to BondedDust's answer above but with (what I think is) slightly easier readability due to use of
stringr
.And that's it. Now it's easy to search — in R — the data to find the constants you want, and assign constants that you will use to variable names, without having to manually type them.
常量包可用。有关用法,请参阅 https://www.r-bloggers .com/2017/07/constants-0-0-1/ 。
例如,您可以像
speed_of_light = with(syms, c0)
那样使用它。The constants package is available. For the usage see https://www.r-bloggers.com/2017/07/constants-0-0-1/ .
E.g. you could use it like
speed_of_light = with(syms, c0)
.