This is going to sound like a basic question but... How do I use universal constants with R?
I was used to being able to just write e or PI in matlab, and these variables were reserved for the universal constants. Are those available in R as well? How to access/use them?
Thanks
Solution : The value of gas constant R is same for all `gases_t` and is independent of the nature of gas. Hence it is called universal gas constant.
There are many physical constants in science, some of the most widely recognized being the speed of light in a vacuum c, the gravitational constant G, the Planck constant h, the electric constant ε0, and the elementary charge e.
That is the volume per unit mole. Ru = 8.314 kJ / (kmol. K) is the universal gas constant, R = Ru /M.
R = 0.0821 L·atm. mol·K. P is in mmHg.
pi
(note the lowercase) is defined but e
is not, although exp(1) is obviously available.
pi # [1] 3.141593
The small number of built-in constants are described :
?Constants
It would be possible to cure this lack-of-e problem with this code:
e <- exp(1) lockBinding("e", globalenv()) e #[1] 2.718282 e <- 2.5 #Error: cannot change value of locked binding for 'e'
(Thanks to Hadley for illustrating this in a different SO thread.) You probably also should go to:
?NumericConstants
Where you will read among other things: "A numeric constant immediately followed by i is regarded as an imaginary complex number."
The other important constants are TRUE
and FALSE
, and while T
and F
can be used in a clean session, T
and F
are not reserved and can be assigned other values, which will then provoke difficult to debug errors, so their use is deprecated. (Although, I suppose one could also use the lockBinding
strategy on them as well.)
There are a few character "constants", such as the 26 item character vectors: letters
, LETTERS
, as well as 12 months in your locale: month.abb
and month.name
. The Greek letters (lower and uppercase) and some math notation can be accessed via methods described in ?plotmath
.
The state.name
and state.abb
mentioned by Tyler below are actually part of the (USA) state
dataset in the "datasets" package which is loaded by default:
library(help="datasets")
If you see an example that uses the cars
, chickwts
, iris
or any of the other dataframes in "datasets", as many help()
examples do, these objects can be assumed to be available on any R user's machine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With