Concept Flow - Variable assignment (<- and =)
Start
Assign value with <- or =
Variable stores value
Use variable later
End
Assign a value to a variable using <- or =, then the variable holds that value for later use.
x <- 5 print(x) y = 10 print(y)
| Step | Code executed | Variable | Value | Output |
|---|---|---|---|---|
| 1 | x <- 5 | x | 5 | |
| 2 | print(x) | x | 5 | 5 |
| 3 | y = 10 | y | 10 | |
| 4 | print(y) | y | 10 | 10 |
| 5 | End of code | - | - | - |
| Variable | Start | After Step 1 | After Step 3 | Final |
|---|---|---|---|---|
| x | undefined | 5 | 5 | 5 |
| y | undefined | undefined | 10 | 10 |
Variable assignment in R: Use <- or = to assign values. Example: x <- 5 or y = 10 Both store values in variables. Variables keep values until changed. Use print() to see variable values.