R Series

Built-in Constants R

In this article, you’ll learn about constants in R. And how to use them.

Constants, as the name suggests, are entities whose value cannot be altered. Basic types of constant are numeric constants and character constants.

Numeric Constants

All numbers fall under this category. They can be of type integerdouble or complex.

It can be checked with the typeof() function.

Numeric constants followed by L are regarded as integer and those followed by i are regarded as complex.

> typeof(101)
[1] "double"
> typeof(101L)
[1] "integer"
> typeof(101i)
[1] "complex"

Also, numeric constants preceded by 0x or 0X are interpreted as hexadecimal numbers.

> 0xf
[1] 15
> 0xaf
[1] 175

Character Constants

Character constants can be represented using either single quotes (‘) or double quotes (“) as delimiters.

> 'Hello World'
[1] "Hello World"
> typeof("Hello World")
[1] "character"

Built in Constants

Some of the built-in constants defined in R

Usage

> LETTERS
 [1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R" "S"
[20] "T" "U" "V" "W" "X" "Y" "Z"
> letters
 [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s"
[20] "t" "u" "v" "w" "x" "y" "z"
> month.abb
 [1] "Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep" "Oct" "Nov" "Dec"
> month.name
 [1] "January"   "February"  "March"     "April"     "May"       "June"
 [7] "July"      "August"    "September" "October"   "November"  "December"
> pi
[1] 3.141593

Details

ConstantDescription
LETTERSthe 26 upper-case letters of the Roman alphabet.
lettersthe 26 lower-case letters of the Roman alphabet.
month.abbthe three-letter abbreviations for the English month names.
month.namethe English names for the months of the year.
pithe ratio of the circumference of a circle to its diameter.

Note: Since R is a case sensitive language therefore TRUE and True are not the same. Here, TRUE is a reserved word and True can be a variable name.

Conclusion

Hence, we saw what are built in constant in R. And how to use those constant like numeric constant, character constant.

This brings the end of this Blog. We really appreciate your time.

Hope you liked it.

Do visit our page www.zigya.com/blog for more informative blogs on Data Science

Keep Reading! Cheers!

Zigya Academy
BEING RELEVANT

Zigya Acadmey

Share
Published by
Zigya Acadmey

Recent Posts

Understanding Standard Form of Numbers: An Explanation With Examples

Through the standard form offers different advantages in mathematical calculations and scientific notation. Firstly, it…

5 months ago

How to deal with stress and anxiety in college

Introduction Stress is a feeling caused by an external trigger that makes us frustrated, such…

6 months ago

Why is Sociology Important These Days?

Sociology is a broad discipline that examines societal issues. It looks at the meaningful patterns…

6 months ago

How to Convert Inches to mm

Some info about Inch Inches are a unique measure that persuades us that even the…

8 months ago

Antilogarithms – Definition, Methods, and Examples

You should be familiar with logarithms to understand antilogarithms in a better manner. Logarithms involve…

10 months ago

नाटककार सुरेंद्र वर्मा

यहां "नाटककार सुरेंद्र वर्मा" पुस्तक की पीडीएफ विद्यार्थी, शोधार्थी और जो इसका अभ्यास के लिए…

10 months ago