8.4 Date 변수에서 정보 추출하기
8.4.1 관련 함수
lubridate 패키지는 Date 변수로부터 특정 정보를 추출할 수 있게 해 주는 다음과 같은 함수들을 제공한다:
day(): 월의 날짜wday(): 평일yday(): 년의 날짜month(): 년의 월year(): 년
8.4.2 Date 변수의 정보 추출 예
# we'll use the first column of our dates dataset
dates$f1## [1] "1989-01-15" "1992-02-13" "1984-03-15"
# day of the month
day(dates$f1)## [1] 15 13 15
# day of the year
yday(dates$f1)## [1] 15 44 75
dates$f1:dates데이터 세트의f1컬럼에 있는 날짜 데이터 확인day(dates$f1):dates데이터 세트의f1컬럼에 있는 날짜 데이터의 해당 월의 날짜yday(dates$f1):dates데이터 세트의f1컬럼에 있는 날짜 데이터의 해당 년도의 날짜
추가적인 예:
# weekday as numbers
wday(dates$f1)## [1] 1 5 5
# weekday with labels
wday(dates$f1, label=TRUE)## [1] 일 목 목
## Levels: 일 < 월 < 화 < 수 < 목 < 금 < 토
# month of the year
month(dates$f1)## [1] 1 2 3
wday(dates$f1): 해당 주의 날짜 (일=1, 월=2, 화=3, 수=4, 목=5, 금=6, 토=7)wday(dates$f1, label=TRUE): 해당 주의 요일month(dates$f1): 해당 월