Home / Programs / Variable assignment in R
🚀 Programming Example

Variable assignment in R

👁 344 Views
💻 Practical Program
📘 Step Learning
A basic concept in (statistical) programming is called a variable.

💻 Program Code

# Assign the value 42 to x
x <- 42

# Print out the value of the variable x
x
                        

🖥 Program Output

> # Assign the value 42 to x
> x <- 42
> 
> # Print out the value of the variable x
> x
[1] 42
                            

📘 Explanation

A basic concept in (statistical) programming is called a variable.

A variable allows you to store a value (e.g. 4) or an object (e.g. a function description) in R. You can then later use this variable's name to easily access the value or the object that is stored within this variable.

You can assign a value 4 to a variable my_var with the command

my_var <- 4
📚 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.