관측치 창 부분집합 추출

R로 시계열 데이터 다루기

Harrison Brown

Graduate Researcher in Geography

시계열 창(Window)

창(Window):

  • 시계열의 부분집합
  • 상위 시계열의 주기를 상속
  • 시작과 끝으로 정의

창의 목적:

  • 지정 구간 데이터 보기
  • 관심 연도/이벤트에 집중
  • 데이터 "가장자리" 관측 무시
R로 시계열 데이터 다루기

시계열 창(Window)

card_prices
2013-01-01 4.88
2013-01-02 5.03
2013-01-03 5.11
...
2014-12-29 4.98
2014-12-30 5.01
2014-12-31 4.94
card_window <- stats::window(
  x = card_prices,
  start = "2013-05-01",
  end = "2013-07-01")
card_window
2013-05-01 4.98
2013-05-02 4.92
...
2013-07-30 5.04
2013-07-31 4.96
  • startend는 포함 범위입니다
R로 시계열 데이터 다루기

논리식으로 부분집합 추출

subset <-
  index(card_price) >= "2013-05-01" &
  index(card_price) <= "2013-07-31"

subset
[1] FALSE FALSE FALSE
[4] FALSE FALSE FALSE
...
card_subset <- card_price[subset]
card_subset
2013-05-01 4.98
2013-05-02 4.92
2013-05-03 5.21
...
2013-07-29 4.89
2013-07-30 5.04
2013-07-31 4.96
R로 시계열 데이터 다루기

특정 날짜 추출

card_price["2014-02-28"]
2014-02-28 
      5.02
class(index(card_price))
[1] "Date"
class("2014-02-28")
[1] "character"
R로 시계열 데이터 다루기

연습해 봅시다!

R로 시계열 데이터 다루기

Preparing Video For Download...