Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create an integer variable with value 10.
R Programming
x <- [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes makes it a string, not an integer.
Using a decimal point makes it a numeric (double), not an integer.
✗ Incorrect
In R, adding L after a number makes it an integer literal.
2fill in blank
mediumComplete the code to check if variable y is of integer type.
R Programming
is.integer([1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the value 10 instead of the variable.
Passing the variable name as a string.
✗ Incorrect
The function is.integer() checks the type of the variable passed to it.
3fill in blank
hardFix the error in the code to convert a numeric value to integer.
R Programming
z <- [1](5.7)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
as.character() converts to string, not integer.Using
as.logical() converts to TRUE/FALSE, not integer.✗ Incorrect
Use as.integer() to convert numeric values to integers in R.
4fill in blank
hardFill both blanks to create a vector of integers from 1 to 5 and check its type.
R Programming
vec <- [1](1:5) is_int <- [2](vec)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
as.numeric instead of as.integer.Using
is.numeric instead of is.integer.✗ Incorrect
as.integer() converts the sequence to integers, and is.integer() checks if the vector is integer type.
5fill in blank
hardFill all three blanks to create an integer vector, convert a number to integer, and check if it is integer.
R Programming
int_vec <- [1](c(2.5, 3.7, 4.1)) num <- [2](5.9) check <- [3](num)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
as.numeric() instead of as.integer().Using
is.numeric() instead of is.integer().✗ Incorrect
Use as.integer() to convert values to integers and is.integer() to check the type.