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
<- c(5L, 8L, 10L)
x
xclass(x)
<- 1:5
y
yclass(y)
<- c(3.5, 8.9, -1.5)
z
zclass(z)
<- c(-5:5)
m
mclass(m)
<- c(2, 4, 6)
a
aclass(a)
<- c(1:5, 3, 4, 5)
b class(b)
<- 1:5
m <- 11:15
n <- c(m,n)
p class(p)
<- vector('numeric', length = 10)
x x
16.3 Example: seq
seq(from = 1, to = 1, by = ((to - from)/(length.out - 1)), length.out = NULL, along.with = NULL, ...)
<- seq(from=0, to=5, by=1)
x
x
<- seq(from=-2, to=10, by=2)
y
y
<- seq(from=1, to=11, by=3)
z
z
<- seq(from=4, to=20, length.out=5)
a
a
seq(10) # same as 1:10
16.4 Example: rep
<- rep(x=2, times=5)
x
x
<- rep(x=2, length.out=5)
y
y
<- rep(x=c(2,3), times=5)
z
z
<- rep(x=c(2,3), each=5)
a
a
<- rep(x=c(2,3), each=5, times=2)
b
b
<- rep(x=c(2,3), each=5, length=12)
c
c
rep(10) # same as 10