2011-11-10 32 views
8

只是好奇 - 是否有一個包含物理常量值的包或數據集?我只問,因爲我現在輸入了273.15(攝氏度到開爾文轉換)錯誤幾次。 =)R中的物理常數

+0

[This](http://stackoverflow.com/q/7214781/324364)問題可能有幫助,並且可能(幾乎)重複。 – joran

回答

3

marelacdielectric都有一些物理常數,但沒有特別說明。 marelac::convert_T將進行溫度轉換。

1

應該很容易下載和解析這個:

http://physics.nist.gov/cuu/Constants/Table/allascii.txt

  • 看起來像固定格式,但這些數字的三倍可能會有點繁瑣。雖然它沒有你的273.15,因爲它可能不是一個定義的「物理常數」。但是如果你需要屏蔽的陰極保護質子磁鐵。媽媽。比例,在那裏。

[實際上從頭開始,那個文件的格式不是很好,而且幾個常量也會破壞大致的固定寬度格式。需要聰明的處理是有用]

+0

格式不是很好,但也不錯。至少它是固定寬度的。一旦寬度被定義,只需要一些'gsub'和'as.numeric' ...就可以直接在數據清理練習的宏偉計劃中使用! – MichaelChirico

2

我可以推薦2種選擇:

1)如果你需要這些常量所有你能利用圖書館。首先在的C2K<-273.15形式的時間。您可以分配常量並將它們存儲在那裏。欲瞭解更多關於此看到http://cran.r-project.org/doc/contrib/Lemon-kickstart/kr_first.html

2)如果你想使用這些文件只是有時在一個文本文件中相同的格式保存的常量如上x<-273.15,然後使用源功能在以下路徑源要將此文件格式: source(C:\Users\PAth to save file text\formulas.txt)

這使您可以更多地控制常量,而不是依賴可能包含或不包含所需內容的包。

+0

這聽起來像一個非常有趣的方法。如果我在那裏存儲了多個轉換,您能詳細說明如何讓源代碼調用特定的轉換嗎?另外,這是將vim設置爲編輯器的一種非常簡單的方法!我怎麼能把命令傳回給R(雖然我試過CTRL + R但是沒有用)? – thequerist

10

這是一個相當大的任務來組裝這些信息,但是在marelac一些熱力學常數可供選擇:

> convert_T(0, "K") 
    K  C  F 
1 0 -273.15 -459.67 

除了將R資源my answer to the question that that @joran cited這些都是進一步的資源在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常數表任務,編輯它,以便轉換爲數字是合理的,這是輸入代碼:

require(foreign) 
fundconst <- read.fwf("allascii.txt", 
         widths=diff(c(0,54, 77, 99, 111)), 
         header=FALSE, skip=12) 
fundconst$V1 <- gsub(" ", "", fundconst[,1]) # strips some of hte white-space 
fundconst$V2 <- as.numeric(gsub(" ", "", fundconst[,2])) 
fundconst$V3 <- as.numeric(gsub(" ", "", fundconst[,3])) 
names(fundconst) <- c("Quantity", "Value", "Uncertainty", "Unit") 
dput(fundconst) 

....這裏是輸入版本:

fundconst <- 
    structure(list(Quantity = c("alpha particle-electron mass ratio", 
"alpha particle mass ", "alpha particle mass energy equivalent ", 
"alpha particle mass energy equivalent in MeV", "alpha particle mass in u", 
"alpha particle molar mass ", "alpha particle-proton mass ratio", 
"Angstrom star ", "atomic mass constant", "atomic mass constant energy equivalent", 
"atomic mass constant energy equivalent in MeV ", "atomic mass unit-electron volt relationship ", 
"atomic mass unit-hartree relationship ", "atomic mass unit-hertz relationship ", 
"atomic mass unit-inverse meter relationship ", "atomic mass unit-joule relationship ", 
"atomic mass unit-kelvin relationship", "atomic mass unit-kilogram relationship", 
"atomic unit of 1st hyperpolarizability", "atomic unit of 2nd hyperpolarizability", 
"atomic unit of action ", "atomic unit of charge ", "atomic unit of charge density ", 
"atomic unit of current", "atomic unit of electric dipole mom. ", 
"atomic unit of electric field ", "atomic unit of electric field gradient", 
"atomic unit of electric polarizability", "atomic unit of electric potential ", 
"atomic unit of electric quadrupole mom. ", "atomic unit of energy ", 
"atomic unit of force", "atomic unit of length ", "atomic unit of mag. dipole mom. ", 
"atomic unit of mag. flux density", "atomic unit of magnetizability", 
"atomic unit of mass ", "atomic unit of mom.um ", "atomic unit of permittivity ", 
"atomic unit of time ", "atomic unit of velocity ", "Avogadro constant ", 
"Bohr magneton ", "Bohr magneton in eV/T ", "Bohr magneton in Hz/T ", 
"Bohr magneton in inverse meters per tesla ", "Bohr magneton in K/T", 
"Bohr radius ", "Boltzmann constant", "Boltzmann constant in eV/K", 
"Boltzmann constant in Hz/K", "Boltzmann constant in inverse meters per kelvin ", 
"characteristic impedance of vacuum", "classical electron radius ", 
"Compton wavelength", "Compton wavelength over 2 pi", "conductance quantum ", 
"conventional value of Josephson constant", "conventional value of von Klitzing constant ", 
"Cu x unit ", "deuteron-electron mag. mom. ratio ", "deuteron-electron mass ratio", 
"deuteron g factor ", "deuteron mag. mom.", "deuteron mag. mom. to Bohr magneton ratio ", 
"deuteron mag. mom. to nuclear magneton ratio", "deuteron mass ", 
"deuteron mass energy equivalent ", "deuteron mass energy equivalent in MeV", 
"deuteron mass in u", "deuteron molar mass ", "deuteron-neutron mag. mom. ratio", 
"deuteron-proton mag. mom. ratio ", "deuteron-proton mass ratio", 
"deuteron rms charge radius", "electric constant ", "electron charge to mass quotient", 
"electron-deuteron mag. mom. ratio ", "electron-deuteron mass ratio", 
"electron g factor ", "electron gyromag. ratio ", "electron gyromag. ratio over 2 pi ", 
"electron-helion mass ratio", "electron mag. mom.", "electron mag. mom. anomaly", 
"electron mag. mom. to Bohr magneton ratio ", "electron mag. mom. to nuclear magneton ratio", 
"electron mass ", "electron mass energy equivalent ", "electron mass energy equivalent in MeV", 
"electron mass in u", "electron molar mass ", "electron-muon mag. mom. ratio ", 
"electron-muon mass ratio", "electron-neutron mag. mom. ratio", 
"electron-neutron mass ratio ", "electron-proton mag. mom. ratio ", 
"electron-proton mass ratio", "electron-tau mass ratio ", "electron to alpha particle mass ratio ", 
"electron to shielded helion mag. mom. ratio ", "electron to shielded proton mag. mom. ratio ", 
"electron-triton mass ratio", "electron volt ", "electron volt-atomic mass unit relationship ", 
"electron volt-hartree relationship", "electron volt-hertz relationship", 
"electron volt-inverse meter relationship", "electron volt-joule relationship", 
"electron volt-kelvin relationship ", "electron volt-kilogram relationship ", 
"elementary charge ", "elementary charge over h", "Faraday constant", 
"Faraday constant for conventional electric current", "Fermi coupling constant ", 
"fine-structure constant ", "first radiation constant", "first radiation constant for spectral radiance", 
"hartree-atomic mass unit relationship ", "hartree-electron volt relationship", 
"Hartree energy", "Hartree energy in eV", "hartree-hertz relationship", 
"hartree-inverse meter relationship", "hartree-joule relationship", 
"hartree-kelvin relationship ", "hartree-kilogram relationship ", 
"helion-electron mass ratio", "helion g factor ", "helion mag. mom.", 
"helion mag. mom. to Bohr magneton ratio ", "helion mag. mom. to nuclear magneton ratio", 
"helion mass ", "helion mass energy equivalent ", "helion mass energy equivalent in MeV", 
"helion mass in u", "helion molar mass ", "helion-proton mass ratio", 
"hertz-atomic mass unit relationship ", "hertz-electron volt relationship", 
"hertz-hartree relationship", "hertz-inverse meter relationship", 
"hertz-joule relationship", "hertz-kelvin relationship ", "hertz-kilogram relationship ", 
"inverse fine-structure constant ", "inverse meter-atomic mass unit relationship ", 
"inverse meter-electron volt relationship", "inverse meter-hartree relationship", 
"inverse meter-hertz relationship", "inverse meter-joule relationship", 
"inverse meter-kelvin relationship ", "inverse meter-kilogram relationship ", 
"inverse of conductance quantum", "Josephson constant", "joule-atomic mass unit relationship ", 
"joule-electron volt relationship", "joule-hartree relationship", 
"joule-hertz relationship", "joule-inverse meter relationship", 
"joule-kelvin relationship ", "joule-kilogram relationship ", 
"kelvin-atomic mass unit relationship", "kelvin-electron volt relationship ", 
"kelvin-hartree relationship ", "kelvin-hertz relationship ", 
"kelvin-inverse meter relationship ", "kelvin-joule relationship ", 
"kelvin-kilogram relationship", "kilogram-atomic mass unit relationship", 
"kilogram-electron volt relationship ", "kilogram-hartree relationship ", 
"kilogram-hertz relationship ", "kilogram-inverse meter relationship ", 
"kilogram-joule relationship ", "kilogram-kelvin relationship", 
"lattice parameter of silicon", "Loschmidt constant (273.15 K, 100 kPa)", 
"Loschmidt constant (273.15 K, 101.325 kPa)", "mag. constant ", 
"mag. flux quantum ", "molar gas constant", "molar mass constant ", 
"molar mass of carbon-12 ", "molar Planck constant ", "molar Planck constant times c ", 
"molar volume of ideal gas (273.15 K, 100 kPa) ", "molar volume of ideal gas (273.15 K, 101.325 kPa) ", 
"molar volume of silicon ", "Mo x unit ", "muon Compton wavelength ", 
"muon Compton wavelength over 2 pi ", "muon-electron mass ratio", 
"muon g factor ", "muon mag. mom.", "muon mag. mom. anomaly", 
"muon mag. mom. to Bohr magneton ratio ", "muon mag. mom. to nuclear magneton ratio", 
"muon mass ", "muon mass energy equivalent ", "muon mass energy equivalent in MeV", 
"muon mass in u", "muon molar mass ", "muon-neutron mass ratio ", 
"muon-proton mag. mom. ratio ", "muon-proton mass ratio", "muon-tau mass ratio ", 
"natural unit of action", "natural unit of action in eV s", "natural unit of energy", 
"natural unit of energy in MeV ", "natural unit of length", "natural unit of mass", 
"natural unit of mom.um", "natural unit of mom.um in MeV/c ", 
"natural unit of time", "natural unit of velocity", "neutron Compton wavelength", 
"neutron Compton wavelength over 2 pi", "neutron-electron mag. mom. ratio", 
"neutron-electron mass ratio ", "neutron g factor", "neutron gyromag. ratio", 
"neutron gyromag. ratio over 2 pi", "neutron mag. mom. ", "neutron mag. mom. to Bohr magneton ratio", 
"neutron mag. mom. to nuclear magneton ratio ", "neutron mass", 
"neutron mass energy equivalent", "neutron mass energy equivalent in MeV ", 
"neutron mass in u ", "neutron molar mass", "neutron-muon mass ratio ", 
"neutron-proton mag. mom. ratio", "neutron-proton mass difference", 
"neutron-proton mass difference energy equivalent", "neutron-proton mass difference energy equivalent MeV", 
"neutron-proton mass difference in u ", "neutron-proton mass ratio ", 
"neutron-tau mass ratio", "neutron to shielded proton mag. mom. ratio", 
"Newtonian constant of gravitation ", "Newtonian constant of gravitation over h-bar c", 
"nuclear magneton", "nuclear magneton in eV/T", "nuclear magneton in inverse meters per tesla", 
"nuclear magneton in K/T ", "nuclear magneton in MHz/T ", "Planck constant ", 
"Planck constant in eV s ", "Planck constant over 2 pi ", "Planck constant over 2 pi in eV s ", 
"Planck constant over 2 pi times c in MeV fm ", "Planck length ", 
"Planck mass ", "Planck mass energy equivalent in GeV", "Planck temperature", 
"Planck time ", "proton charge to mass quotient", "proton Compton wavelength ", 
"proton Compton wavelength over 2 pi ", "proton-electron mass ratio", 
"proton g factor ", "proton gyromag. ratio ", "proton gyromag. ratio over 2 pi ", 
"proton mag. mom.", "proton mag. mom. to Bohr magneton ratio ", 
"proton mag. mom. to nuclear magneton ratio", "proton mag. shielding correction", 
"proton mass ", "proton mass energy equivalent ", "proton mass energy equivalent in MeV", 
"proton mass in u", "proton molar mass ", "proton-muon mass ratio", 
"proton-neutron mag. mom. ratio", "proton-neutron mass ratio ", 
"proton rms charge radius", "proton-tau mass ratio ", "quantum of circulation", 
"quantum of circulation times 2", "Rydberg constant", "Rydberg constant times c in Hz", 
"Rydberg constant times hc in eV ", "Rydberg constant times hc in J", 
"Sackur-Tetrode constant (1 K, 100 kPa)", "Sackur-Tetrode constant (1 K, 101.325 kPa)", 
"second radiation constant ", "shielded helion gyromag. ratio", 
"shielded helion gyromag. ratio over 2 pi", "shielded helion mag. mom. ", 
"shielded helion mag. mom. to Bohr magneton ratio", "shielded helion mag. mom. to nuclear magneton ratio ", 
"shielded helion to proton mag. mom. ratio ", "shielded helion to shielded proton mag. mom. ratio", 
"shielded proton gyromag. ratio", "shielded proton gyromag. ratio over 2 pi", 
"shielded proton mag. mom. ", "shielded proton mag. mom. to Bohr magneton ratio", 
"shielded proton mag. mom. to nuclear magneton ratio ", "speed of light in vacuum", 
"standard acceleration of gravity", "standard atmosphere ", "standard-state pressure ", 
"Stefan-Boltzmann constant ", "tau Compton wavelength", "tau Compton wavelength over 2 pi", 
"tau-electron mass ratio ", "tau mass", "tau mass energy equivalent", 
"tau mass energy equivalent in MeV ", "tau mass in u ", "tau molar mass", 
"tau-muon mass ratio ", "tau-neutron mass ratio", "tau-proton mass ratio ", 
"Thomson cross section ", "triton-electron mass ratio", "triton g factor ", 
"triton mag. mom.", "triton mag. mom. to Bohr magneton ratio ", 
"triton mag. mom. to nuclear magneton ratio", "triton mass ", 
"triton mass energy equivalent ", "triton mass energy equivalent in MeV", 
"triton mass in u", "triton molar mass ", "triton-proton mass ratio", 
"unified atomic mass unit", "von Klitzing constant ", "weak mixing angle ", 
"Wien frequency displacement law constant", "Wien wavelength displacement law constant " 
), Value = c(7294.2995361, 6.64465675e-27, 5.97191967e-10, 3727.37924, 
4.001506179125, 0.004001506179125, 3.97259968933, 1.00001495e-10, 
1.660538921e-27, 1.492417954e-10, 931.494061, 931494061, 34231776.845, 
2.2523427168e+23, 751300660420000, 1.492417954e-10, 10809540800000, 
1.660538921e-27, 3.206361449e-53, 6.23538054e-65, 1.054571726e-34, 
1.602176565e-19, 1081202338000, 0.00662361795, 8.47835326e-30, 
514220652000, 9.717362e+21, 1.6487772754e-41, 27.21138505, 4.486551331e-40, 
4.35974434e-18, 8.23872278e-08, 5.2917721092e-11, 1.854801936e-23, 
235051.7464, 7.891036607e-29, 9.10938291e-31, 1.99285174e-24, 
1.112650056e-10, 2.418884326502e-17, 2187691.26379, 6.02214129e+23, 
9.27400968e-24, 5.7883818066e-05, 13996245550, 46.6864498, 0.67171388, 
5.2917721092e-11, 1.3806488e-23, 8.6173324e-05, 20836618000, 
69.503476, 376.730313461, 2.8179403267e-15, 2.4263102389e-12, 
3.86159268e-13, 7.7480917346e-05, 4.835979e+14, 25812.807, 1.00207697e-13, 
-0.0004664345537, 3670.4829652, 0.8574382308, 4.33073489e-27, 
0.0004669754556, 0.8574382308, 3.34358348e-27, 3.00506297e-10, 
1875.612859, 2.013553212712, 0.002013553212712, -0.44820652, 
0.307012207, 1.99900750097, 2.1424e-15, 8.854187817e-12, -175882008800, 
-2143.923498, 0.00027244371095, -2.00231930436153, 176085970800, 
28024.95266, 0.00018195430761, -9.2847643e-24, 0.00115965218076, 
-1.00115965218076, -1838.2819709, 9.10938291e-31, 8.18710506e-14, 
0.510998928, 0.00054857990946, 5.4857990946e-07, 206.7669896, 
0.00483633166, 960.9205, 0.00054386734461, -658.2106848, 0.00054461702178, 
0.000287592, 0.000137093355578, 864.058257, -658.2275971, 0.00018192000653, 
1.602176565e-19, 1.07354415e-09, 0.03674932379, 241798934800000, 
806554.429, 1.602176565e-19, 11604.519, 1.782661845e-36, 1.602176565e-19, 
241798934800000, 96485.3365, 96485.3321, 1.166364e-05, 0.0072973525698, 
3.74177153e-16, 1.191042869e-16, 2.9212623246e-08, 27.21138505, 
4.35974434e-18, 27.21138505, 6579683920729000, 21947463.13708, 
4.35974434e-18, 315775.04, 4.85086979e-35, 5495.8852754, -4.255250613, 
-1.074617486e-26, -0.001158740958, -2.127625306, 5.00641234e-27, 
4.49953902e-10, 2808.391482, 3.0149322468, 0.0030149322468, 2.9931526707, 
4.4398216689e-24, 4.135667516e-15, 1.5198298460045e-16, 3.335640951e-09, 
6.62606957e-34, 4.7992434e-11, 7.37249668e-51, 137.035999074, 
1.3310250512e-15, 1.23984193e-06, 4.556335252755e-08, 299792458, 
1.986445684e-25, 0.01438777, 2.210218902e-42, 12906.4037217, 
4.8359787e+14, 6700535850, 6.24150934e+18, 2.29371248e+17, 1.509190311e+33, 
5.03411701e+24, 7.2429716e+22, 1.112650056e-17, 9.2510868e-14, 
8.6173324e-05, 3.1668114e-06, 20836618000, 69.503476, 1.3806488e-23, 
1.536179e-40, 6.02214129e+26, 5.60958885e+35, 2.061485968e+34, 
1.356392608e+50, 4.52443873e+41, 8.987551787e+16, 6.5096582e+39, 
5.431020504e-10, 2.6516462e+25, 2.6867805e+25, 1.2566370614e-06, 
2.067833758e-15, 8.3144621, 0.001, 0.012, 3.9903127176e-10, 0.119626565779, 
0.022710953, 0.022413968, 1.205883301e-05, 1.00209952e-13, 1.173444103e-14, 
1.867594294e-15, 206.7682843, -2.0023318418, -4.49044807e-26, 
0.00116592091, -0.00484197044, -8.89059697, 1.883531475e-28, 
1.692833667e-11, 105.6583715, 0.1134289267, 0.0001134289267, 
0.1124545177, -3.183345107, 0.1126095272, 0.0594649, 1.054571726e-34, 
6.58211928e-16, 8.18710506e-14, 0.510998928, 3.86159268e-13, 
9.10938291e-31, 2.73092429e-22, 0.510998928, 1.28808866833e-21, 
299792458, 1.3195909068e-15, 2.1001941568e-16, 0.00104066882, 
1838.6836605, -3.82608545, 183247179, 29.1646943, -9.6623647e-27, 
-0.00104187563, -1.91304272, 1.674927351e-27, 1.505349631e-10, 
939.565379, 1.008664916, 0.001008664916, 8.892484, -0.68497934, 
2.30557392e-30, 2.0721465e-13, 1.29333217, 0.00138844919, 1.00137841917, 
0.52879, -0.68499694, 6.67384e-11, 6.70837e-39, 5.05078353e-27, 
3.1524512605e-08, 0.02542623527, 0.00036582682, 7.62259357, 6.62606957e-34, 
4.135667516e-15, 1.054571726e-34, 6.58211928e-16, 197.3269718, 
1.616199e-35, 2.17651e-08, 1.220932e+19, 1.416833e+32, 5.39106e-44, 
95788335.8, 1.32140985623e-15, 2.1030891047e-16, 1836.15267245, 
5.585694713, 267522200.5, 42.5774806, 1.410606743e-26, 0.00152103221, 
2.792847356, 2.5694e-05, 1.672621777e-27, 1.503277484e-10, 938.272046, 
1.007276466812, 0.001007276466812, 8.88024331, -1.45989806, 0.99862347826, 
8.775e-16, 0.528063, 0.0003636947552, 0.0007273895104, 10973731.568539, 
3289841960364000, 13.60569253, 2.179872171e-18, -1.1517078, -1.1648708, 
0.01438777, 203789465.9, 32.43410084, -1.074553044e-26, -0.001158671471, 
-2.127497718, -0.761766558, -0.7617861313, 267515326.8, 42.5763866, 
1.410570499e-26, 0.001520993128, 2.792775598, 299792458, 9.80665, 
101325, 1e+05, 5.670373e-08, 6.97787e-16, 1.11056e-16, 3477.15, 
3.16747e-27, 2.84678e-10, 1776.82, 1.90749, 0.00190749, 16.8167, 
1.89111, 1.89372, 6.652458734e-29, 5496.9215267, 5.957924896, 
1.504609447e-26, 0.001622393657, 2.978962448, 5.0073563e-27, 
4.50038741e-10, 2808.921005, 3.0155007134, 0.0030155007134, 2.9937170308, 
1.660538921e-27, 25812.8074434, 0.2223, 58789254000, 0.0028977721 
), Uncertainty = c(2.9e-06, 2.9e-34, 2.6e-17, 8.2e-05, 6.2e-11, 
6.2e-14, 3.6e-10, 9e-17, 7.3e-35, 6.6e-18, 2.1e-05, 21, 0.024, 
1.6e+14, 530000, 6.6e-18, 9800000, 7.3e-35, 7.1e-61, 2.8e-72, 
4.7e-42, 3.5e-27, 24000, 1.5e-10, 1.9e-37, 11000, 2.1e+14, 1.6e-50, 
6e-07, 9.9e-48, 1.9e-25, 3.6e-15, 1.7e-20, 4.1e-31, 0.0052, 1.3e-37, 
4e-38, 8.8e-32, NA, 1.2e-28, 0.00071, 2.7e+16, 2e-31, 3.8e-14, 
310, 1e-06, 6.1e-07, 1.7e-20, 1.3e-29, 7.8e-11, 19000, 6.3e-05, 
NA, 2.7e-24, 1.6e-21, 2.5e-22, 2.5e-14, NA, NA, 2.8e-20, 3.9e-12, 
1.5e-06, 7.2e-09, 1e-34, 3.9e-12, 7.2e-09, 1.5e-34, 1.3e-17, 
4.1e-05, 7.7e-11, 7.7e-14, 1.1e-07, 2.4e-09, 1.8e-10, 2.1e-18, 
NA, 3900, 1.8e-05, 1.1e-13, 5.3e-13, 3900, 0.00062, 1.7e-13, 
2.1e-31, 2.7e-13, 2.7e-13, 7.5e-07, 4e-38, 3.6e-21, 1.1e-08, 
2.2e-13, 2.2e-16, 5.2e-06, 1.2e-10, 0.00023, 3.2e-13, 5.4e-06, 
2.2e-13, 2.6e-08, 5.5e-14, 1e-05, 7.2e-06, 1.7e-13, 3.5e-27, 
2.4e-17, 8.1e-10, 5300000, 0.018, 3.5e-27, 0.011, 3.9e-44, 3.5e-27, 
5300000, 0.0021, 0.0043, 5e-11, 2.4e-12, 1.7e-23, 5.3e-24, 2.1e-17, 
6e-07, 1.9e-25, 6e-07, 33000, 0.00011, 1.9e-25, 0.29, 2.1e-42, 
5e-06, 5e-08, 2.7e-34, 1.4e-11, 2.5e-08, 2.2e-34, 2e-17, 6.2e-05, 
2.5e-09, 2.5e-12, 2.5e-09, 3.1e-33, 9.1e-23, 7.6e-12, NA, 2.9e-41, 
4.4e-17, 3.3e-58, 4.4e-08, 9.4e-25, 2.7e-14, 2.3e-19, NA, 8.8e-33, 
1.3e-08, 9.8e-50, 4.2e-06, 1.1e+07, 300, 1.4e+11, 1e+10, 6.7e+25, 
2.2e+17, 6.6e+16, NA, 8.4e-20, 7.8e-11, 2.9e-12, 19000, 6.3e-05, 
1.3e-29, 1.4e-46, 2.7e+19, 1.2e+28, 9.1e+26, 6e+42, 2e+34, NA, 
5.9e+33, 8.9e-18, 2.4e+19, 2.4e+19, NA, 4.6e-23, 7.5e-06, NA, 
NA, 2.8e-19, 8.4e-11, 2.1e-08, 2e-08, 8e-13, 5.3e-20, 3e-22, 
4.7e-23, 5.2e-06, 1.3e-09, 1.5e-33, 6.3e-10, 1.2e-10, 2.2e-07, 
9.6e-36, 8.6e-19, 3.5e-06, 2.9e-09, 2.9e-12, 2.8e-09, 8.4e-08, 
2.8e-09, 5.4e-06, 4.7e-42, 1.5e-23, 3.6e-21, 1.1e-08, 2.5e-22, 
4e-38, 1.2e-29, 1.1e-08, 8.3e-31, NA, 1.1e-24, 1.7e-25, 2.5e-10, 
1.1e-06, 9e-07, 43, 6.9e-06, 2.3e-33, 2.5e-10, 4.5e-07, 7.4e-35, 
6.6e-18, 2.1e-05, 4.3e-10, 4.3e-13, 2.2e-07, 1.6e-07, 7.6e-37, 
6.8e-20, 4.2e-07, 4.5e-10, 4.5e-10, 4.8e-05, 1.6e-07, 8e-15, 
8e-43, 1.1e-34, 2.2e-17, 5.6e-10, 3.3e-10, 1.7e-07, 2.9e-41, 
9.1e-23, 4.7e-42, 1.5e-23, 4.4e-06, 9.7e-40, 1.3e-12, 7.3e+14, 
8.5e+27, 3.2e-48, 2.1, 9.4e-25, 1.5e-25, 7.5e-07, 4.6e-08, 6.3, 
1e-06, 3.3e-34, 1.2e-11, 2.3e-08, 1.4e-08, 7.4e-35, 6.6e-18, 
2.1e-05, 9e-11, 9e-14, 2.2e-07, 3.4e-07, 4.5e-10, 5.1e-18, 4.8e-05, 
2.4e-13, 4.7e-13, 5.5e-05, 17000, 3e-07, 9.6e-26, 2.3e-06, 2.3e-06, 
1.3e-08, 5.1, 8.1e-07, 2.7e-34, 1.4e-11, 2.5e-08, 1.1e-08, 3.3e-09, 
6.6, 1e-06, 3.5e-34, 1.7e-11, 3e-08, NA, NA, NA, NA, 2.1e-13, 
6.3e-20, 1e-20, 0.31, 2.9e-31, 2.6e-14, 0.16, 0.00017, 1.7e-07, 
0.0015, 0.00017, 0.00017, 1.3e-37, 5e-06, 7.6e-08, 3.8e-34, 2.1e-11, 
3.8e-08, 2.2e-34, 2e-17, 6.2e-05, 2.5e-09, 2.5e-12, 2.5e-09, 
7.3e-35, 8.4e-06, 0.0021, 53000, 2.6e-09), Unit = structure(c(NA, 
38L, 28L, 53L, 66L, 40L, NA, 41L, 38L, 28L, 53L, 17L, 16L, 24L, 
45L, 28L, 36L, 38L, 13L, 14L, 32L, 6L, 9L, 4L, 8L, 68L, 69L, 
12L, 67L, 10L, 28L, 58L, 41L, 34L, 65L, 35L, 38L, 39L, 21L, 1L, 
43L, 57L, 34L, 20L, 26L, 47L, 37L, 41L, 29L, 18L, 25L, 46L, 60L, 
41L, 41L, 41L, 63L, 27L, 60L, 41L, NA, NA, NA, 34L, NA, NA, 38L, 
28L, 53L, 66L, 40L, NA, NA, NA, 41L, 21L, 7L, NA, NA, NA, 64L, 
56L, NA, 34L, NA, NA, NA, 38L, 28L, 53L, 66L, 40L, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, 28L, 66L, 16L, 24L, 45L, 28L, 
36L, 38L, 6L, 5L, 11L, 15L, 23L, NA, 71L, 72L, 66L, 17L, 28L, 
17L, 24L, 45L, 28L, 36L, 38L, NA, NA, 34L, NA, NA, 38L, 28L, 
53L, 66L, 40L, NA, 66L, 17L, 3L, 45L, 28L, 36L, 38L, NA, 66L, 
17L, 16L, 24L, 28L, 36L, 38L, 60L, 27L, 66L, 17L, 16L, 24L, 45L, 
36L, 38L, 66L, 17L, 16L, 24L, 45L, 28L, 38L, 66L, 17L, 16L, 24L, 
45L, 28L, 36L, 41L, 48L, 48L, 59L, 73L, 31L, 40L, 40L, 33L, 30L, 
52L, 52L, 52L, 41L, 41L, 41L, NA, NA, 34L, NA, NA, NA, 38L, 28L, 
53L, 66L, 40L, NA, NA, NA, NA, 32L, 19L, 28L, 53L, 41L, 38L, 
39L, 55L, 62L, 43L, 41L, 41L, NA, NA, NA, 64L, 56L, 34L, NA, 
NA, 38L, 28L, 53L, 66L, 40L, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, 51L, 2L, 34L, 20L, 47L, 37L, 56L, 32L, 19L, 32L, 19L, 54L, 
41L, 38L, 22L, 36L, 62L, 7L, 41L, 41L, NA, NA, 64L, 56L, 34L, 
NA, NA, NA, 38L, 28L, 53L, 66L, 40L, NA, NA, NA, 41L, NA, 50L, 
50L, 45L, 24L, 17L, 28L, NA, NA, 42L, 64L, 56L, 34L, NA, NA, 
NA, NA, 64L, 56L, 34L, NA, NA, 43L, 44L, 61L, 61L, 70L, 41L, 
41L, NA, 38L, 28L, 53L, 66L, 40L, NA, NA, NA, 49L, NA, NA, 34L, 
NA, NA, 38L, 28L, 53L, 66L, 40L, NA, 38L, 60L, NA, 25L, 42L), .Label = c(" s", 
"(GeV/c^2)^-2", "16 E_h", "A", "A J^-1", "C", "C kg^-1", "C m", 
"C m^-3", "C m^2", "C mol^-1", "C^2 m^2 J^-1", "C^3 m^3 J^-2", 
"C^4 m^4 J^-3", "C_90 mol^-1", "E_h", "eV", "eV K^-1", "eV s", 
"eV T^-1", "F m^-1", "GeV", "GeV^-2", "Hz", "Hz K^-1", "Hz T^-1", 
"Hz V^-1", "J", "J K^-1", "J m mol^-1", "J mol^-1 K^-", "J s", 
"J s mol^-1", "J T^-1", "J T^-2", "K", "K T^-1", "kg", "kg m s^-1", 
"kg mol^-1", "m", "m K", "m s^-1", "m s^-2", "m^-1", "m^-1 K^-1", 
"m^-1 T^-1", "m^-3", "m^2", "m^2 s^-1", "m^3 kg^-1 s^", "m^3 mol^-1", 
"MeV", "MeV fm", "MeV/c", "MHz T^-1", "mol^-1", "N", "N A^-2", 
"ohm", "Pa", "s", "S", "s^-1 T^-1", "T", "u", "V", "V m^-1", 
"V m^-2", "W m^-2 K^-4", "W m^2", "W m^2 sr^-1", "Wb"), class = "factor")), .Names = c("Quantity", 
"Value", "Uncertainty", "Unit"), row.names = c(NA, -334L), class = "data.frame") 
+3

我們是否可以將它包裝在CRAN的包裝上? r-forge上有一個「常量」包,意思是做類似的事情,但我從來沒有想到它真的有用。我認爲這些數據,也許還包裝到data.frame的超類中,以顯示很好的單位和名稱(使用打印方法等),可以爲許多人提供有用的參考。我們還可以包含一些轉換函數,一個分類,常見常量的別名,如c,R等,以及一個好的搜索函數。 – baptiste

+0

@baptiste:我認爲這將是一個好主意。如果你已經開始了一個常量包,我會很樂意成爲一個貢獻者。我的想法是圍繞基本單位組織一個包裹:長度,時間,質量,收費,然後包括衍生的類別,如密度,濃度(數量/體積),沸點,熱容量等。 –

+0

@Dwin是的,我想知道捕捉單元特定屬性的最佳格式是什麼。面向對象的框架會在這裏工作嗎?也許參考類?一個數字會附加一個維度(單位),並且會有相關的方法在各個單位系統之間進行轉換。 – baptiste

0

這是對NIST CODATA物理常數表的另一個解析。這與BondedDust的答案類似,但由於使用stringr(我認爲是這樣),可讀性稍差。


    #parsing NIST CODATA data for physical constants 
    require(stringr) #simplifies regex usage syntax in R 

    #web page with data 
    link <- 'http://physics.nist.gov/cuu/Constants/Table/allascii.txt' 

    allstr <- readLines(link) 
    codata.str <- allstr[11:345] #data starts at line 11 

    #at least 3 spaces separate columns 
    codata.str2 <- str_replace_all(codata.str, '[ ]{3,100}', '\t') 

    #four cols in source table 
    codata.mat <- str_split_fixed(codata.str2, '\t', n=4) 

    #eliminate spaces separating every three decimal digits 
    codata.mat[,c(2,3)] <- str_replace_all(codata.mat[,c(2,3)], " ", "") 

    codata <- data.frame(quantity = codata.mat[,1], 
          value  = as.numeric(codata.mat[,2]), 
          uncertainty = as.numeric(codata.mat[,3]), 
          units  = codata.mat[,4] 
       ) 

就是這樣。現在可以很容易地在R中搜索數據以查找所需的常量,並將常量用於變量名稱,而無需手動輸入它們。


    > codata[str_detect(codata$quantity, 'electron mass'),] 
             quantity  value uncertainty units 
    2  alpha particle-electron mass ratio 7.294300e+03  2.9e-06  
    63   deuteron-electron mass ratio 3.670483e+03  1.5e-06  
    89       electron mass 9.109383e-31  4.0e-38 kg 
    90   electron mass energy equivalent 8.187105e-14  3.6e-21  J 
    91 electron mass energy equivalent in MeV 5.109989e-01  1.1e-08 MeV 
    92      electron mass in u 5.485799e-04  2.2e-13  u 
    130    helion-electron mass ratio 5.495885e+03  5.0e-06  
    195    muon-electron mass ratio 2.067683e+02  5.2e-06  
    223   neutron-electron mass ratio 1.838684e+03  1.1e-06  
    264    proton-electron mass ratio 1.836153e+03  7.5e-07  
    310    tau-electron mass ratio 3.477150e+03  3.1e-01  
    320    triton-electron mass ratio 5.496922e+03  5.0e-06 

    > me.u < codata[str_detect(codata$quantity, 'electron mass in u'),'value'] 
    > me.u 
    [1] 0.0005485799