R Variables Introduction
Variables in R are used to store data values. R is dynamically typed, meaning you do not need to declare the data type of a variable. You can assign values to variables using the assignment operator <-
or =
.
1. Variable Assignment
You can create variables and assign values to them in R:
# Assigning values to variables
x <- 10
Output:
[1] 10
y = 20
Output:
[1] 20
z <- "Hello, World!"
Output:
[1] "Hello, World!"
Code Explanation: x
and y
are assigned numeric values using <-
and =
, while z
is assigned a string value using <-
. Both assignment operators work similarly, but <-
is more commonly used in R.
Key Takeaways
- Variables are used to store values for later use.
- R allows flexible assignment using
<-
or=
.