1.5 Value types
Some common value types in R are double
, integer
, logical
, character
, and datetime
. Mostly, you will work with double, logical, and character. You can check the type of the values in an object using an is.
function as shown here.
Double
Values of type double
are numbers with decimal places.
## [1] 5.23
## [1] FALSE
## [1] TRUE
Integer
An integer
value is a whole number and requires an L
to be added after the number to tell R the number is to be stored as an integer, not double.
## [1] 5
## [1] TRUE
## [1] FALSE
NOTE: Unless you tell R something is an integer, it will store it as double. Which is just as well since you will mostly be working with doubles, not integers. In general, you can ignore this distinction but occasionally it comes up so it is good to know it exists.
Logical
Logical values are very common in R as we often are comparing things to see if they are the same or not.
## [1] TRUE TRUE FALSE
## [1] TRUE
Character
A character
value is a single string surrounded by quotes.
## [1] TRUE
Datetime
Date and time values can be rather complicated to work with. For more information about working with datetime variables, see the chapter “Dates and Times” in the “R for Data Science” (Wickham and Grolemund 2017).
## [1] "2024-06-25 12:34:32 EDT"
## [1] "POSIXct" "POSIXt"