0
0
R Programmingprogramming~20 mins

Variable assignment (<- and =) in R Programming - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
R Assignment Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of variable assignment with <- and =
What is the output of the following R code?
x <- 5
y = 10
z <- x + y
print(z)
R Programming
x <- 5
y = 10
z <- x + y
print(z)
ANULL
B510
CError: object 'z' not found
D15
Attempts:
2 left
💡 Hint
Remember that both <- and = assign values to variables in R.
Predict Output
intermediate
2:00remaining
Difference between <- and = in function arguments
What will this R code print?
f <- function(a = 3) { a * 2 }
f()
f <- function(a <- 3) { a * 2 }
f()
R Programming
f <- function(a = 3) { a * 2 }
f()
f <- function(a <- 3) { a * 2 }
f()
A6 and Error
B6 and 6
CError and 6
DError and Error
Attempts:
2 left
💡 Hint
Check how default arguments are assigned in R functions.
🔧 Debug
advanced
2:00remaining
Why does this assignment fail?
Consider this R code:
5 <- x

Why does this cause an error?
R Programming
5 <- x
ABecause <- cannot be used with numbers
BBecause x is not defined
CBecause 5 is a constant and cannot be assigned a value
DBecause assignment requires = not <-
Attempts:
2 left
💡 Hint
Think about what can be on the left side of an assignment.
Predict Output
advanced
2:00remaining
Output of chained assignments
What is the output of this R code?
a <- b <- 7
print(a)
print(b)
R Programming
a <- b <- 7
print(a)
print(b)
A7 and 7
B7 and NULL
CNULL and 7
DError: object 'b' not found
Attempts:
2 left
💡 Hint
Remember that assignment in R returns the assigned value.
📝 Syntax
expert
2:00remaining
Which assignment causes a syntax error?
Which of these R assignments will cause a syntax error?
Ax <- 10
B<- z 30
Cy = 20
Da <- b <- 5
Attempts:
2 left
💡 Hint
Look carefully at the position of the assignment operator.