Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print "Hello, world!" in the R console.
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.
Putting the whole print statement inside print().
✗ Incorrect
In R, to print text, you use print() with the text inside quotes.
2fill in blank
mediumComplete the code to assign the number 10 to a variable named x.
R Programming
x [1] 10
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using == which is for comparison, not assignment.
Using = which works but <- is preferred style.
✗ Incorrect
In R, the preferred way to assign a value to a variable is using the <- operator.
3fill in blank
hardFix the error in the code to correctly run a script file named "script.R".
R Programming
source([1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not putting the filename in quotes.
Using the filename without extension.
✗ Incorrect
The source() function requires the filename as a string inside quotes.
4fill in blank
hardFill both blanks to create a vector of numbers from 1 to 5 and print it.
R Programming
numbers <- [1]([2])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using seq without parameters.
Not using c() to create a vector.
✗ Incorrect
Use c() to combine numbers into a vector. 1:5 creates numbers from 1 to 5.
5fill in blank
hardFill all three blanks to read a CSV file named "data.csv", assign it to a variable, and print the first rows.
R Programming
[1] <- read.csv([2]) head([3])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not putting filename in quotes.
Using different variable names inconsistently.
✗ Incorrect
Assign the result of read.csv() to a variable, then use head() to print first rows.