5. 꿈꾸는데이터디자이너 시즌2
Join two tables
thiswk title
1 War Room
2 Straight Outta Compton
3 A Walk in the Woods
4 Mission Impossible : Rogue Nation
5 The Transporter Refueled
6 No Escape
7 Inside Out
8 The Man From U.N.C.L.E.
9 Un Gallo Con Muchos Huevos
10 Sinister 2
lastwk title
1 Straight Outta Compton
2 War Room
3 Mission Impossible : Rogue Nation
4 No Escape
5 Sinister 2
6 The Man From U.N.C.L.E.
7 Hitman: Agent 47
8 Ant-Man
9 Jurassic World
10 The Gift
6. 꿈꾸는데이터디자이너 시즌2
Join two tables
thiswk title
1 War Room
2 Straight Outta Compton
3 A Walk in the Woods
4 Mission Impossible : Rogue Nation
5 The Transporter Refueled
6 No Escape
7 Inside Out
8 The Man From U.N.C.L.E.
9 Un Gallo Con Muchos Huevos
10 Sinister 2
lastwk title
1 Straight Outta Compton
2 War Room
3 Mission Impossible : Rogue Nation
4 No Escape
5 Sinister 2
6 The Man From U.N.C.L.E.
7 Hitman: Agent 47
8 Ant-Man
9 Jurassic World
10 The Gift
7. 꿈꾸는데이터디자이너 시즌2
inner join
thiswk title
1 War Room
2 Straight Outta Compton
4 Mission Impossible : Rogue Nation
6 No Escape
8 The Man From U.N.C.L.E.
10 Sinister 2
lastwk title
1 Straight Outta Compton
2 War Room
3 Mission Impossible : Rogue Nation
4 No Escape
5 Sinister 2
6 The Man From U.N.C.L.E.
8. 꿈꾸는데이터디자이너 시즌2
inner join
thiswk title lastwk
1 War Room 2
2 Straight Outta Compton 1
4 Mission Impossible : Rogue Nation 3
6 No Escape 4
8 The Man From U.N.C.L.E. 6
10 Sinister 2 5
9. 꿈꾸는데이터디자이너 시즌2
left join
thiswk title
1 War Room
2 Straight Outta Compton
3 A Walk in the Woods
4 Mission Impossible : Rogue Nation
5 The Transporter Refueled
6 No Escape
7 Inside Out
8 The Man From U.N.C.L.E.
9 Un Gallo Con Muchos Huevos
10 Sinister 2
lastwk title
1 Straight Outta Compton
2 War Room
3 Mission Impossible : Rogue Nation
4 No Escape
5 Sinister 2
6 The Man From U.N.C.L.E.
10. 꿈꾸는데이터디자이너 시즌2
left join
thiswk title lastwk
1 War Room 2
2 Straight Outta Compton 1
3 A Walk in the Woods NA
4 Mission Impossible : Rogue Nation 3
5 The Transporter Refueled NA
6 No Escape 4
7 Inside Out NA
8 The Man From U.N.C.L.E. 6
9 Un Gallo Con Muchos Huevos NA
10 Sinister 2 5
13. 꿈꾸는데이터디자이너 시즌2
데이터 불러올 때 주의사항
- 데이터가 로드되지 않는 경우 살펴볼 것
- 파일이 프로젝트 폴더에 들어가 있는가 ?
- 프로젝트 폴더로 파일을 옮긴다(권장)
- 파일이 있는 폴더를 setwd()로 지정(Project : none 일경우)
- 프로젝트 폴더 안에다가 새로운 하위폴더를 만들었나?
- 파일 경로에 해당 폴더까지 추가
- 안전하게 tab 버튼을 이용하자
- stringsAsFactors 옵션 여부
- 한글 인코딩
14. 꿈꾸는데이터디자이너 시즌2
dplyr join
# 기준이 되는 열의 이름이 같을 때
%>%
????_join( , by = )
# 기준이 되는 열의 이름이 다를 때
%>%
????_join( ,
by = c( = ))
15. 꿈꾸는데이터디자이너 시즌2
dplyr join
movie_thiswk %>%
inner_join(movie_lastwk, by = 'title')
movie_thiswk %>%
left_join(movie_lastwk, by = 'title')
movie_thiswk %>%
left_join(movie_data, by = c('title' = 'titl'))
31. 꿈꾸는데이터디자이너 시즌2
str_replace(' ',' ',' ')
꿈꾸는 꿈꾸는 데이터 디자이너
나는 꿈꾸는 데이터 디자이너
str_replace_all(' ',' ',' ')
꿈꾸는 꿈꾸는 데이터 디자이너
나는 나는 데이터 디자이너
32. 꿈꾸는데이터디자이너 시즌2
str_detect(원본 문자열, 찾으려고 하는 패턴/단어)
str_detect(movie_data$distributor, 'Pictures')
movie_data %>%
filter(str_detect(distributor, 'Pictures'))
distributor
1 TriStar Pictures
2 Universal Pictures
3 Broad Green Pictures
4 Paramount Pictures
5 Walt Disney Studios Motion Pictures
6 Warner Bros. Pictures Distribution
......
33. 꿈꾸는데이터디자이너 시즌2
특정 단어로 끝나는 항목 찾기
str_detect(movie_data$distributor, 'Pictures$')
movie_data %>%
filter(str_detect(distributor, 'Pictures$'))
distributor
1 TriStar Pictures
2 Universal Pictures
3 Broad Green Pictures
4 Paramount Pictures
5 Walt Disney Studios Motion Pictures
6 Warner Bros. Pictures Distribution
......
34. 꿈꾸는데이터디자이너 시즌2
특정 단어로 시작하는 항목 찾기
str_detect(movie_data$distributor, '^Sony')
movie_data %>%
filter(str_detect(distributor, '^Sony'))
distributor
1 Sony Pictures Releasing
2 Sony Pictures Classics
3 Sony Pictures Classics
4 Sony Pictures Classics
......
36. 꿈꾸는데이터디자이너 시즌2
# 현재 시각
time = Sys.time()
# 요일
weekdays(time)
# 월
months(time)
# 분기
quarters(time)
37. 꿈꾸는데이터디자이너 시즌2
strftime(time, "%m/%d") 09/09
strftime(time, "%Y-%m-%d") 2015-09-09
strftime(time, "%y-%m-%d") 15-09-09
strftime(time, "%Y") 2015
# 일요일을 0으로 두었을 때 요일 표기
strftime(time, "%w") 3
다양한 포맷에 대해서는
?strftime 을 통해 살펴볼 수 있다
38. 꿈꾸는데이터디자이너 시즌2
str_time = '20150909'
date_time = as.Date(str_time, format = '%Y%m%d')
date_time + 30
# 결과물
> "2015-10-09"
chr to Date