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
pi(note the lowercase) is defined buteis not, although exp(1) is obviously available.The small number of built-in constants are described :
It would be possible to cure this lack-of-e problem with this code:
(Thanks to Hadley for illustrating this in a different SO thread.)
You probably also should go to:
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
TRUEandFALSE, and whileTandFcan be used in a clean session,TandFare 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 thelockBindingstrategy 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.abbandmonth.name. The Greek letters (lower and uppercase) and some math notation can be accessed via methods described in?plotmath.The
state.nameandstate.abbmentioned by Tyler below are actually part of the (USA)statedataset in the “datasets” package which is loaded by default:If you see an example that uses the
cars,chickwts,irisor any of the other dataframes in “datasets”, as manyhelp()examples do, these objects can be assumed to be available on any R user’s machine.