# assign value 7.2 to object a
(a <- 7.2) # remember, wrapping in parentheses prints to console[1] 7.2
2023-02-03
Double
Integer
Character
Logical
typeof()
# assign value 7.2 to object a
(a <- 7.2) # remember, wrapping in parentheses prints to console[1] 7.2
typeof(a)[1] "double"
(b <- 7)[1] 7
typeof(b)[1] "double"
Doubles can have 0 as decimal
L)(c <- 7L)[1] 7
typeof(c)[1] "integer"
""
(d <- "Hello, world")[1] "Hello, world"
(e <- "7")[1] "7"
typeof(e)[1] "character"
b, c, and e into the console separately. What do you see?b + c.b + e.TRUE or FALSE (notice always all upper case)>, >=, <, <=, ==, !=, %in%
a[1] 7.2
a > 5[1] TRUE
d[1] "Hello, world"
(mytest <- d == "Good-bye, world")[1] FALSE
typeof(mytest)[1] "logical"
==
Note
We use
== for logical equals<- for assigning objects= for assigning function argument values to argument names%in% operator: “is contained in”(subjects <- c("01", "02", "03", "04", "05"))[1] "01" "02" "03" "04" "05"
"03" %in% subjects[1] TRUE
"06" %in% subjects[1] FALSE
! before test string!"06" %in% subjects[1] TRUE
Factors
Dates
typeof(i)[1] "integer"
is.<type>() functions: is.logical(), is.numeric(), is.character()
as.<type>() functions:(m <- "TRUE")[1] "TRUE"
typeof(m)[1] "character"
(n <- as.logical(m))[1] TRUE
typeof(n)[1] "logical"
NA represents missing valuesEach data type has its own type of NA
Check with is.na()
NaN means “not a number” (undefined)0 / 0 = NaNInf and -Inf represent infinity and negative infinity1 / 0 = Inf
-1 / 0 = -Inf