seq()

Published by onesixx on

seq()

Sequence Generation

seq()
# [1] 1
seq(from=1, to=1, by=0 
    #by = ((to-from)/(length.out-1)),
    #length.out = NULL
    #along.with = NULL, ...
    )
seq(16) 
#  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16
1:16
seq(1,16)    
seq(1,16,1)        # seq(from=1, to=16, by=1)

seq(to=16)
seq(from=16)
seq(length.out=16)  

by

원하는 간격으로 (by)

seq(1, 6, by = 2)     # matches 'end'
# [1] 1 3 5
seq(1, 6, by = pi)    # stays below 'end'
# [1] 1.00 4.14
seq(1, 6, by = 3)
# [1] 1 4
seq(1.575, 2.125, by = 0.05)
# [1] 1.57 1.62 1.68 1.73 1.77 1.82 1.88 1.93 1.98 2.02 2.08 2.12

length.out

원하는 출력 길이 (length.out) (균등하게 간격으로)조절

seq(0, 1, length.out=11)
# [1] 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0

seq_len()

seq_len(length.out)함수는 1에서 N까지 자연수(계수)를 구성
seq_len(16)
#  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16
seq(from=11, length.out=16)
#  [1] 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26

along.with

시퀀스가 다른 벡터와 같은 길이를 가져야한다면,
along.with 를 length.out = length(x) 의 약자로 사용할 수 있습니다.

x = 1:8
seq(1, 6, along.with=x)
# [1] 2.000000 2.428571 2.857143 3.285714 3.714286 4.142857 4.571429 5.000000

seq_along()

seq_along(along.with)은 기존 객체의 인덱스를 반환
x=c("a","b","c","d","e","f")  # letters[1:6]
seq_along(x)
# [1] 1 2 3 4 5 6
seq(from=11, along.with=x)
# [1] 11 12 13 14 15 16

sequence()

음수가 아닌 인수의 시퀀스 벡터를 만드는 이전 함수 sequence()

sequence(4)               # seq(4)
# [1] 1 2 3 4
sequence(c(3, 2))         # c(seq(3), seq(2))
# [1] 1 2 3 1 2
sequence(c(3, 2, 5))      # c(seq(3), seq(2), seq(5))
# [1] 1 2 3 1 2 1 2 3 4 5
Categories: Reshaping

onesixx

Blog Owner

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x