Home / Programs / Basic data types in R
🚀 Programming Example

Basic data types in R

👁 425 Views
💻 Practical Program
📘 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
                        

🖥 Program 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!
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.