일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- 위도경도
- 구글 지오코드
- 코딩
- 파이썬
- 카카오APi
- #비정형#카카오api#api#크롤링
- 셀레니움
- 숫자빼고 중복되는 코드동작법
- #K-means #Clustering
- #비정형 데이터 #네이버 #지도 #크롤링
- #크롤링 #웹문서
- #위도#경도#비정형데이터#크롤링
- 웹크롤링
- 파이썬 셀레니움
- 웹매크로 #세잔느
- Today
- Total
지방이의 Data Science Lab
[R] 날짜 열로 할 수 있는 컬럼관리 방법 본문
(데이터 크기가 커질수록 lubridate함수로 관리하는 것보다 string으로 들고 있는 것이 억만배 가볍다. 월별 추출도 string단위로 긁어오는게 훨씬 빠른 속도를 보인다.)
[2019.12.25 => 20191225]
library(stringr)
monthly$관리년월 = str_replace_all(monthly$관리년월, "[.]", "")
monthly$yearmonth = str_sub(monthly$yearmonth,1,7)
[201912 => 2019-12-01]
'몇일' 변수를 꼭 추가해야 하는 경우가 있다. (시각화)
예를들어 x축에 날짜를 넣고 싶은 경우가 그렇다.
그럴때 보통 사용하는 코드가 이것:
temp$yearmonth = as.Date(ymd(paste0(temp$yearmonth,'01')))
[20191225=>2019-12-25]
library(stringi)
stri_sub(CUSTINFO$SALDT,5,4)="-";stri_sub(CUSTINFO$SALDT,8,7)="-" #20190324 => 2019-03-24
[요일]
방법1:
CUSTINFO$SALDT=as.Date(CUSTINFO$SALDT)
CUSTINFO$wday=strftime(CUSTINFO$SALDT,"%A")
방법2:
library(lubridate)
CUSTINFO$SALDT=ymd(CUSTINFO$SALDT)
CUSTINFO$wdays=wday(CUSTINFO$SALDT,label=TRUE)
[계절]
library(stringr)
temp1$month = str_sub(temp1$yearmonth,5,6)
temp1$month = as.numeric(temp1$month)
seasons = function(x){
if(x %in% 2:4) return('Spring')
if(x %in% 5:7) return('Summer')
if(x %in% 8:10) return('Fall')
if(x %in% c(11,12,1)) return('Winter')
}
temp1$season = sapply(temp1$month, seasons)
'Data Analysis > 깨R지식' 카테고리의 다른 글
[R] 조건에 맞는 특정 데이터 추출 (0) | 2019.12.30 |
---|---|
[R] x축 날짜 데이터 시각화 (0) | 2019.12.28 |
[R] get_dummies와 같은 형태 (0) | 2019.12.28 |
[R] 계절컬럼 파생변수 추가 (0) | 2019.12.27 |
[R] 평균값으로 imputation하는 방법 (0) | 2019.07.25 |