Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if the variable x is numeric.
R Programming
is_numeric <- is[1](x) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using is.integer() instead of is.numeric()
Using typeof() instead of is.numeric()
✗ Incorrect
The function is.numeric() checks if a variable is numeric in R.
2fill in blank
mediumComplete the code to convert the variable y to a character type.
R Programming
y_char <- as[1](y)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using as.numeric() instead of as.character()
Using as.logical() instead of as.character()
✗ Incorrect
The function as.character() converts a variable to character type in R.
3fill in blank
hardFix the error in the code to check if z is a logical type.
R Programming
is_logical <- is[1](z) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using is.numeric() instead of is.logical()
Using is.character() instead of is.logical()
✗ Incorrect
The correct function to check logical type is is.logical().
4fill in blank
hardFill both blanks to create a named vector with names as characters and values as numeric.
R Programming
vec <- c([1] = 1, [2] = 2)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using numbers as names without quotes
Using unquoted names
✗ Incorrect
Vector names must be character strings, so use quotes around letters.
5fill in blank
hardFill all three blanks to create a list with a numeric, a character, and a logical element.
R Programming
my_list <- list(num = [1], char = [2], logi = [3])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Putting numbers inside quotes for numeric
Using FALSE instead of TRUE for logical
✗ Incorrect
The list elements are numeric (42), character ("hello"), and logical (TRUE).