0
0
R Programmingprogramming~20 mins

Vector creation with c() in R Programming - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Vector Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of combining different types with c()
What is the output of this R code?
x <- c(1, TRUE, "3", 4.5)
print(x)
R Programming
x <- c(1, TRUE, "3", 4.5)
print(x)
A[1] 1 1 3 4.5
B[1] "1" "TRUE" "3" "4.5"
C[1] "1" "1" "3" "4.5"
D[1] 1 TRUE "3" 4.5
Attempts:
2 left
💡 Hint
Remember that c() converts all elements to the most flexible type to keep them in one vector.
Predict Output
intermediate
1:30remaining
Length of vector created with c()
What is the length of the vector created by this code?
v <- c(NA, NULL, 5, c(2, 3))
length(v)
R Programming
v <- c(NA, NULL, 5, c(2, 3))
length(v)
A5
B2
C3
D4
Attempts:
2 left
💡 Hint
Remember that NULL is ignored inside c(), but NA counts as an element.
🔧 Debug
advanced
1:30remaining
Why does this c() call produce an error?
This code produces an error. What is the cause?
v <- c(1, 2, 3, , 5)
R Programming
v <- c(1, 2, 3, , 5)
ASyntax error due to missing value between commas
BNo error, code runs fine
CRuntime error because c() cannot handle more than 4 elements
DType error because 5 is not compatible with previous numbers
Attempts:
2 left
💡 Hint
Check the commas carefully inside the c() function.
🧠 Conceptual
advanced
1:30remaining
Behavior of c() with named elements
What is the output of this R code?
v <- c(a=1, b=2, 3)
names(v)
R Programming
v <- c(a=1, b=2, 3)
names(v)
A[1] "a" "b" "3"
B[1] "a" "b" "c"
C[1] "a" "b" ""
D[1] NULL
Attempts:
2 left
💡 Hint
Only elements explicitly named get names; unnamed elements have empty names.
Predict Output
expert
2:00remaining
Output of nested c() calls with mixed types
What is the output of this R code?
v <- c(1, c(TRUE, "text"), 3.5)
print(v)
R Programming
v <- c(1, c(TRUE, "text"), 3.5)
print(v)
A[1] "1" "TRUE" "text" "3.5"
B[1] 1 1 "text" 3.5
C[1] "1" "1" "text" "3.5"
D[1] 1 TRUE "text" 3.5
Attempts:
2 left
💡 Hint
Remember that c() flattens nested vectors and coerces types to the most flexible one.