Recall & Review
beginner
What function in R checks the type of an object?
The
typeof() function returns the internal type or storage mode of any R object.Click to reveal answer
beginner
How do you convert a numeric value to a character string in R?
Use the
as.character() function to convert numeric values to character strings.Click to reveal answer
beginner
What does the
is.numeric() function do in R?It checks if an object is of numeric type and returns
TRUE if it is, otherwise FALSE.Click to reveal answer
intermediate
How can you convert a character vector to a factor in R?
Use the
as.factor() function to convert a character vector into a factor, which is useful for categorical data.Click to reveal answer
intermediate
What happens if you try to convert a non-numeric character string to numeric using
as.numeric()?R returns
NA with a warning because the string cannot be interpreted as a number.Click to reveal answer
Which function checks if an object is a character vector in R?
✗ Incorrect
The
is.character() function returns TRUE if the object is a character vector.What does
typeof(42L) return in R?✗ Incorrect
The suffix L makes 42 an integer, so
typeof(42L) returns "integer".Which function converts a factor back to a character vector?
✗ Incorrect
Use
as.character() to convert factors to character vectors.What will
as.numeric("abc") return?✗ Incorrect
R returns NA and a warning because "abc" cannot be converted to a number.
Which function tells you the class of an object in R?
✗ Incorrect
class() returns the object's class, which is a higher-level description than typeof().Explain how to check the type of a variable and convert it to another type in R.
Think about functions that check type and those that change type.
You got /5 concepts.
Describe what happens when you try to convert a non-numeric string to numeric in R and how to handle it.
Consider what R returns and how you might check for conversion success.
You got /4 concepts.