Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print "Hello, world!" in R.
R Programming
print([1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the text
Using print without quotes
Using echo instead of print
✗ Incorrect
In R, to print text, you use print() with the text in quotes.
2fill in blank
mediumComplete the code to assign the value 10 to variable x in R.
R Programming
[1] <- 10
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Putting 10 on the left side
Using = instead of <-
Using assign() function incorrectly
✗ Incorrect
In R, the assignment operator <- assigns values to variables.
3fill in blank
hardFix the error in the code to calculate the sum of numbers 1 to 5.
R Programming
total <- [1](1:5)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using add() instead of sum()
Using range() which returns min and max
Using variable names instead of functions
✗ Incorrect
The sum() function calculates the total of a numeric vector in R.
4fill in blank
hardFill both blanks to create a vector of numbers from 1 to 10 and get its length.
R Programming
numbers <- [1](1, 10) length_of_numbers <- [2](numbers)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using c() instead of seq() for sequence
Using sum() instead of length()
Mixing up function names
✗ Incorrect
seq(1, 10) creates a sequence from 1 to 10; length() returns the number of elements.
5fill in blank
hardFill all three blanks to create a named vector with scores and get the names of the vector.
R Programming
scores <- c([1] = 90, [2] = 85, [3] = 88) names(scores)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using numbers instead of names
Using incorrect subject names
Forgetting to name the vector elements
✗ Incorrect
Named vectors use names like Math, Science, English to label scores.