R supports various variable types, each with its own characteristics. Understanding these types is crucial for data manipulation and analysis.
2024
R supports various variable types, each with its own characteristics. Understanding these types is crucial for data manipulation and analysis.
# Example of numeric type a <- 3.14 class(a)
## [1] "numeric"
L to the number.# Example of integer type b <- 42L class(b)
## [1] "integer"
# Example of character type c <- "Hello, R!" class(c)
## [1] "character"
# Example of logical type d <- TRUE class(d)
## [1] "logical"
# Example of factor type
e <- factor(c("Low", "Medium", "High"), levels = c("Low", "Medium", "High"))
class(e)
## [1] "factor"
levels(e)
## [1] "Low" "Medium" "High"
What is the class of the variable defined by x <- 2.5?
Which of the following is the correct way to create a character variable containing the text “R is fun”?
x <- R is funx <- "R is fun"x <- c(R is fun)x <- 'R' 'is' 'fun'x <- "R is fun". Text must be enclosed in quotes to be treated as character data in R.
True or False: The expression class(100L) will return integer.
L to a number specifies it as an integer in R.
How do you specify a logical variable in R?
x <- logicalx <- "TRUE"x <- TRUEx <- Tx <- TRUE. However, 4. x <- T is also technically correct as T is shorthand for TRUE in R, but using TRUE is preferred for clarity.
Which function is used to create factors in R?
factor()as.factor()createFactor()factor() creates a factor, and as.factor() converts an existing variable to a factor.