Spis treści:
Eksploracja danych z bibliotekami dplyr, tidyr oraz
stringr
- Podzbiory kolumn
- Filtrowanie wierszy
- Operatory logiczne, algebra Boola, prawa de Morgana
- Tworzenie nowych kolumn (1x Challenge)
- Wartości brakujące
- Manipulowanie tekstem (3x Challenge)
- Agregacja danych (1x Challenge)
- Tabele przestawne, dane w formacie long oraz wide
- Łączenie tabel
Przydatne materiały:
- dplyr
cheatsheet
- tidyr
cheatsheet
- stringr
cheatsheet
- ggplot2
cheatsheet
- A.
Kassambara - Guide to Create Beautiful Graphics in R.
Dane pochodzą ze strony https://flixgem.com/ (wersja zbioru danych z dnia 12 marca 2021). Dane zawierają informacje na temat 9425 filmów i seriali dostępnych na Netlix.
CHALLENGE 1: Jaki jest najstarszy film Woody’ego Allena dostępny na Netflixie?
dane %>%
group_by(Title)%>%
filter(Director == "Woody Allen", Series.or.Movie == "Movie") %>%
mutate(Release = Release.Date %>% as.Date(format = '%m/%d/%Y')) %>%
select(Title, Release) %>%
arrange(Release)%>%
head()
## # A tibble: 6 × 2
## # Groups: Title [6]
## Title Release
## <chr> <date>
## 1 Everything You Always Wanted to Know About Sex But Were Afraid to … 1972-08-06
## 2 Sleeper 1973-12-17
## 3 Love and Death 1975-07-18
## 4 A Midsummer Nights Sex Comedy 1982-07-16
## 5 Manhattan Murder Mystery 1993-08-18
## 6 Scoop 2006-07-28
#Najstarszym filmem jest “Everything You Always Wanted to Know About Sex But Were Afraid to Ask”.
CHALLENGE 2: Jakie są trzy najwyżej oceniane komedie dostępne w języku polskim?
dane %>%
filter(Genre %>% str_detect("Comedy")) %>%
filter(Languages %>% str_detect('Polish')) %>%
arrange(-IMDb.Score) %>%
select(Title, IMDb.Score) %>%
top_n(3)
## Selecting by IMDb.Score
## Title IMDb.Score
## 1 Rake 8.5
## 2 Teddy Bear 8.2
## 3 Trois Couleurs - Blanc 7.6
CHALLENGE 3: Dla produkcji z lat 2019 oraz 2020 jaki jest średni czas między premierą a pojawieniem się na Netflixie?
dane$Release.Date <- as.Date(dane$Release.Date, format = "%m/%d/%Y")
dane$Netflix.Release.Date <- as.Date(dane$Netflix.Release.Date, format = "%m/%d/%Y")
dane %>%
drop_na(Release.Date, Netflix.Release.Date) %>%
mutate(Rok = lubridate::year(Release.Date),
Roznica = Netflix.Release.Date - Release.Date) %>%
filter(Rok %>% between(2019,2020)) %>%
group_by(Rok) %>%
summarize(Srednia = mean(Roznica) %>% round(0))%>%
print()
## # A tibble: 2 × 2
## Rok Srednia
## <dbl> <drtn>
## 1 2019 152 days
## 2 2020 31 days
CHALLENGE 4: Jakie są najpopularniejsze tagi dla produkcji dostępnych w języku polskim?
dane %>%
filter(Languages %>%
str_detect('Polish')) %>%
separate_rows(Tags, sep = ',') %>%
group_by(Tags = tolower(Tags)) %>%
summarise(Suma = n()) %>% top_n(10) %>%
select(Tags, Suma)%>%
arrange(desc(Suma))%>%
print()
## Selecting by Suma
## # A tibble: 10 × 2
## Tags Suma
## <chr> <int>
## 1 dramas 50
## 2 polish movies 29
## 3 polish dramas 17
## 4 movies based on books 15
## 5 tv dramas 15
## 6 international dramas 14
## 7 international movies 13
## 8 polish tv shows 13
## 9 comedies 12
## 10 movies based on real life 11
## Selecting by Suma
CHALLENGE 5: Jakie są średnie oceny filmów wyprodukowanych w poszczególnych dekadach (tzn. lata 60, 70, 80, 90 etc.)?
dane$Release.Date <- as.Date(dane$Release.Date, format = "%m/%d/%Y")
dane %>%
mutate(rok = lubridate::year(Release.Date), decade = floor(rok/10)*10) %>%
group_by(decade) %>%
filter(decade %in% c('1960', '1970', '1980', '1990', '2000', '2010', '2020'))%>%
summarize(avg_imdb_score = mean(IMDb.Score, na.rm = TRUE) %>% round(2))%>%
print()
## # A tibble: 7 × 2
## decade avg_imdb_score
## <dbl> <dbl>
## 1 1960 7.46
## 2 1970 7.33
## 3 1980 7.11
## 4 1990 6.88
## 5 2000 6.85
## 6 2010 6.94
## 7 2020 7.04