Section 16 Vector: Numeric
16.1 Functions
| Function | Concept | Example |
|---|---|---|
c |
Concatenate | c(2,4,6,8,10) |
: |
Colon | c(1:10) |
seq |
Sequence | seq(from=10, to=20, by=2) |
rep |
Repeat | rep(x=c(2,4), each=10) |
16.2 Example: Numeric vector
x <- c(5L, 8L, 10L)
x
class(x)
y <- 1:5
y
class(y)
z <- c(3.5, 8.9, -1.5)
z
class(z)
m <- c(-5:5)
m
class(m)
a <- c(2, 4, 6)
a
class(a)
b <- c(1:5, 3, 4, 5)
class(b)
m <- 1:5
n <- 11:15
p <- c(m,n)
class(p)
x <- vector('numeric', length = 10)
x16.3 Example: seq
seq(from = 1, to = 1, by = ((to - from)/(length.out - 1)), length.out = NULL, along.with = NULL, ...)
x <- seq(from=0, to=5, by=1)
x
y <- seq(from=-2, to=10, by=2)
y
z <- seq(from=1, to=11, by=3)
z
a <- seq(from=4, to=20, length.out=5)
a
seq(10) # same as 1:1016.4 Example: rep
x <- rep(x=2, times=5)
x
y <- rep(x=2, length.out=5)
y
z <- rep(x=c(2,3), times=5)
z
a <- rep(x=c(2,3), each=5)
a
b <- rep(x=c(2,3), each=5, times=2)
b
c <- rep(x=c(2,3), each=5, length=12)
c
rep(10) # same as 10