Home / Programs / Basic data types in R
Programming Example

Basic data types in R

👁 425 Views
💻 Practical Program
📘 Step by Step Learning

R works with numerous data types. Some of the most basic types to get started are:

  • Decimal values like 4.5 are called numerics.
  • Natural numbers like 4 are called integers. Integers are also numerics.
  • Boolean values (TRUE or FALSE) are called logical.
  • Text (or string) values are called characters.

Note how the quotation marks on the right indicate that "some text" is a character.

Program Code

# Change my_numeric to be 42
my_numeric <- 42.5

# Change my_character to be "universe"
my_character <- "some text"

# Change my_logical to be FALSE
my_logical <- TRUE

Output

> # Change my_numeric to be 42
> my_numeric <- 42
> 
> # Change my_character to be "universe"
> my_character <- "universe"
> 
> # Change my_logical to be FALSE
> my_logical <- FALSE

Explanation

Change the value of the: my_numeric variable to 42. my_character variable to "universe". Note that the quotation marks indicate that "universe" is a character. my_logical variable to FALSE. Note that R is case sensitive!

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.