logical1 <- TRUE
logical2 <- FALSE
# The class() function outputs the data type of the object
class(logical1)[1] "logical"print(logical2)[1] FALSEprint(class(logical2))[1] "logical"There are 6 types of data in R that are important to know, but the essential ones are logical, numeric, and character.
Logical Also known as boolean data, logical data is shown as TRUE or FALSE values:
logical1 <- TRUE
logical2 <- FALSE
# The class() function outputs the data type of the object
class(logical1)[1] "logical"print(logical2)[1] FALSEprint(class(logical2))[1] "logical"Numeric represents all data types that are real numbers with or with out decimal points.
height <- 5.5
acres <- 1000
class(height)[1] "numeric"print(acres)[1] 1000print(class(acres))[1] "numeric"Character specifies character or string values in a variable such as a singular character ‘A’ or a string of characters in ‘Apple’.
# Use '' or "" to show it's a string of characters
motorsports <- "formula1"
print(motorsports)[1] "formula1"print(class(motorsports))[1] "character"Integer specifies real values without decimal points
# the suffix i specifies its imaginary data.
complex <- 3 + 2i
print(class(integer))[1] "function"Raw specifies values as raw bytes
# convert character to raw
raw_variable <- charToRaw("Welcome to Programiz")
print(raw_variable) [1] 57 65 6c 63 6f 6d 65 20 74 6f 20 50 72 6f 67 72 61 6d 69 7aprint(class(raw_variable))[1] "raw"# convert raw to character
char_variable <- rawToChar(raw_variable)
print(char_variable)[1] "Welcome to Programiz"print(class(char_variable))[1] "character"