0
0
R Programmingprogramming~5 mins

Variable assignment (<- and =) in R Programming - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the <- operator do in R?
The <- operator assigns a value to a variable in R. It stores the value on the right into the variable on the left.
Click to reveal answer
beginner
How is the = operator used in R for variable assignment?
The = operator can also assign values to variables in R, similar to <-, but <- is preferred for clarity in scripts.
Click to reveal answer
beginner
Which operator is preferred for assignment in R scripts: <- or =?
The <- operator is preferred for assignment in R scripts because it clearly shows assignment and avoids confusion with function arguments.
Click to reveal answer
intermediate
Can you use both <- and = interchangeably for assignment in R?
Yes, both <- and = can assign values to variables, but <- is recommended for assignments and = is often used for function arguments.
Click to reveal answer
beginner
What happens if you write x <- 5 and then x = 10 in R?
The variable x first gets the value 5, then it is updated to 10. Both assignments change the value stored in x.
Click to reveal answer
Which operator is traditionally used for variable assignment in R?
A->
B=
C==
D<-
What does the = operator do in R when used outside function calls?
AAssigns a value to a variable
BChecks equality
CCreates a function
DComments out code
Which of these is NOT a correct way to assign 10 to variable x in R?
A10 -> x
Bx = 10
Cx == 10
Dx <- 10
If you write x <- 5 and then x = 7, what is the value of x?
A7
B5
C12
DError
Why is <- preferred over = for assignment in R scripts?
ABecause = is only for comparisons
BBecause <- is clearer and avoids confusion with function arguments
CBecause = causes errors
DBecause <- is faster
Explain how to assign values to variables in R using both <- and = operators.
Think about how you store a value in a box labeled with a name.
You got /4 concepts.
    Describe why <- is preferred over = for variable assignment in R scripts.
    Consider how to make your code easier to read and understand.
    You got /4 concepts.