Multiple Variables

R allows you to assign values to multiple variables in a single line, making code more efficient and compact.

Examples of Multiple Variable Assignment

# Assigning the same value to multiple variables
a <- b <- c <- 5

Output:

[1] 5
[1] 5
[1] 5
# Using semicolons to assign values in one line
p <- 1; q <- 2; r <- 3

Output:

[1] 1
[1] 2
[1] 3

Code Explanation: a, b, and c are assigned the value 5 simultaneously. Using semicolons allows you to assign values to p, q, and r in a single line.

Key Takeaways

  • You can assign the same value to multiple variables at once.
  • Using semicolons allows you to write multiple assignments on a single line.