R Data types

A variable in R stores data of different types, like numeric, string, float, etc. An R variable gets created when a value is assigned i.e. mentioning any specific type name is not required.

The following are the datatypes in R:

  • numeric
  • integer
  • complex
  • character
  • logical/ boolean
  • vectors
  • lists

Let us understand the datatypes one by one with examples:

Numeric data type in R

The numeric type stores numbers, decimal numbers, etc. Let us see an example:

Output

Integer data type in R

The integer type stores integers and an appended L is used to declare an integer in R. Let us see an example:

Output

Complex data type in R

The complex type stores complex numbers. It consists of the Real and Imaginary parts with i being imaginary. Let us see an example:

Output

Character data type in R

The character/ string type stores characters and strings. Use a single quote or double quote while creating a character or string type. Let us see an example:

Output

Logical/ boolean data type in R

The boolean type has two values, TRUE or FALSE. Let us see an example:

Output

Vectors in R

The vectors are elements of the same time, separated by a comma. The c() function combines such elements and forms a vector i.e. to create a Vector, use the c() in R programming. Let us see an example:

Output

Lists in R

If you want to add elements of different data types, then use the lists in R. The list() function is used in R to create a List. Let us see an example:

Output

If you liked the tutorial, spread the word and share the link and our website Studyopedia with others.


For Videos, Join Our YouTube Channel: Join Now


Read More:

R Variables
R Loops
Studyopedia Editorial Staff
contact@studyopedia.com

We work to create programming tutorials for all.

No Comments

Post A Comment

Discover more from Studyopedia

Subscribe now to keep reading and get access to the full archive.

Continue reading