library(readxl)
library(dplyr)
 㠼㸳p㠼㸳b㠼㸳P㠼㸱[㠼㸳W 㠼㸱edplyr㠼㸱f 㠼㸲̓o㠼㸱[㠼㸳W㠼㸳㠼㸷㠼㸳㤼㸳 3.6.2 㠼㸲挼㹣 R 㠼㸲̉戼㹡㠼㸲ő愼㸲㠼㸲攼㸷㠼㸲攼㹡㠼㸲܂戼㸵㠼㸲戼㹤 Registered S3 method overwritten by 'dplyr':
  method           from
  print.rowwise_df     

 㠼㹥㤼㹦㠼㸲̃p㠼㸳b㠼㸳P㠼㸱[㠼㸳W㠼㸲昼㸰㤼㸵t㠼㸲愼㹦㠼㸹挼㸱㠼㸲愼㸶㠼㸲܂戼㸷: 㠼㸱edplyr㠼㸱f 

 㠼㸸ȉ戼㹡㠼㸲̃I㠼㸳u㠼㸳W㠼㸳F㠼㸳N㠼㸳g㠼㸲挼㹤 㠼㸱epackage:stats㠼㸱f 㠼㸲愼㸹㠼㸲攼㸷㠼㸳}㠼㸳X㠼㸳N㠼㸲戼㸳㠼㸲攼㹡㠼㸲Ă愼㸲㠼㸲܂戼㸷: 

     filter, lag 

 㠼㸸ȉ戼㹡㠼㸲̃I㠼㸳u㠼㸳W㠼㸳F㠼㸳N㠼㸳g㠼㸲挼㹤 㠼㸱epackage:base㠼㸱f 㠼㸲愼㸹㠼㸲攼㸷㠼㸳}㠼㸳X㠼㸳N㠼㸲戼㸳㠼㸲攼㹡㠼㸲Ă愼㸲㠼㸲܂戼㸷: 

     intersect, setdiff, setequal, union 
mydata = read_excel("C:/user/document/Temple University/DTA101/week05/itunes.xlsx", sheet = "cleaned")
myyear = format(as.Date(mydata$`date added`),"%Y")
mydata = cbind(mydata, myyear)

num_genre = length(unique(mydata$genre))
num_artist = length(unique(mydata$artist))
num_album = length(unique(mydata$`album name`))
num_song = length(unique(mydata$`song name`))

Summary

genre: 62
artist: 2134
album: 516
song: 6258

Tendency

tempdata1 = data.frame(year = mydata$myyear, album = mydata$`album name`)
albumdata = tempdata1 %>% group_by(year) %>% summarise(album = length(unique(album)))
barplot(albumdata$album, names.arg = albumdata$year, main = 'imported album/year')

Most played genre

mygenre = data.frame(genre = mydata$genre, plays = mydata$plays)
mygenre = mygenre %>% group_by(genre) %>% summarise(plays = sum(plays))
mygenre = mygenre[order(mygenre$plays, decreasing = TRUE),]
head(mygenre, 10)

Most played artist

myartist = data.frame(artist = mydata$artist, plays = mydata$plays)
myartist = myartist %>% group_by(artist) %>% summarise(plays = sum(plays))
myartist = myartist[order(myartist$plays, decreasing = TRUE),]
head(myartist, 10)

Most played album

myalbum = data.frame(album = mydata$`album name`, plays = mydata$plays)
myalbum = myalbum %>% group_by(album) %>% summarise(plays = sum(plays))
myalbum = myalbum[order(myalbum$plays, decreasing = TRUE),]
head(myalbum, 10)

Most played song

mysong = data.frame(song = mydata$`song name`, plays = mydata$plays)
mysong = mysong %>% group_by(song) %>% summarise(plays = sum(plays))
mysong = mysong[order(mysong$plays, decreasing = TRUE),]
head(mysong, 10)
LS0tDQp0aXRsZTogIlIgTm90ZWJvb2siDQpvdXRwdXQ6IGh0bWxfbm90ZWJvb2sNCi0tLQ0KDQoNCmBgYHtyfQ0KbGlicmFyeShyZWFkeGwpDQpsaWJyYXJ5KGRwbHlyKQ0KDQpteWRhdGEgPSByZWFkX2V4Y2VsKCJDOi91c2VyL2RvY3VtZW50L1RlbXBsZSBVbml2ZXJzaXR5L0RUQTEwMS93ZWVrMDUvaXR1bmVzLnhsc3giLCBzaGVldCA9ICJjbGVhbmVkIikNCm15eWVhciA9IGZvcm1hdChhcy5EYXRlKG15ZGF0YSRgZGF0ZSBhZGRlZGApLCIlWSIpDQpteWRhdGEgPSBjYmluZChteWRhdGEsIG15eWVhcikNCg0KbnVtX2dlbnJlID0gbGVuZ3RoKHVuaXF1ZShteWRhdGEkZ2VucmUpKQ0KbnVtX2FydGlzdCA9IGxlbmd0aCh1bmlxdWUobXlkYXRhJGFydGlzdCkpDQpudW1fYWxidW0gPSBsZW5ndGgodW5pcXV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