double - floating point numerical values (default numerical type)
typeof(2.5)
[1] "double"
typeof(3)
[1] "double"
integer - integer numerical values (indicated with an L)
typeof(3L)
[1] "integer"
typeof(1:3)
[1] "integer"
Concatenation
Vectors can be constructed using the c() function.
Numeric vector:
c(1, 2, 3)
[1] 1 2 3
Character vector:
c("Hello", "World!")
[1] "Hello" "World!"
Vector made of vectors:
c(c("hi", "hello"), c("bye", "jello"))
[1] "hi" "hello" "bye" "jello"
Converting between types
with intention…
x <-1:3x
[1] 1 2 3
typeof(x)
[1] "integer"
y <-as.character(x)y
[1] "1" "2" "3"
typeof(y)
[1] "character"
Converting between types
with intention…
x <-c(TRUE, FALSE)x
[1] TRUE FALSE
typeof(x)
[1] "logical"
y <-as.numeric(x)y
[1] 1 0
typeof(y)
[1] "double"
Converting between types
without intention…
c(2, "Just this one!")
[1] "2" "Just this one!"
R will happily convert between various types without complaint when different types of data are concatenated in a vector, and that’s not always a great thing!