reisijad=read_csv("http://www.tlu.ee/~jaagup/andmed/muu/estonia_reisijad.txt") nrow(reisijad) reisijad %>% nrow() reisijad %>% filter(Country=='Estonia') %>% nrow() nrow(reisijad[reisijad$Country=='Estonia',])/nrow(reisijad) sum(reisijad$Country=='Estonia')/nrow(reisijad) round(100*sum(reisijad$Country=='Estonia')/nrow(reisijad)) reisijad %>% filter(Country=='Estonia') %>% {round(100*nrow(.)/nrow(reisijad))} eestireisijad=filter(reisijad, Country=="Estonia") eestireisijad %>% filter(Survived==1) %>% nrow()/nrow(eestireisijad) reisijad %>% group_by(Country) %>% summarise(kogus=n(), k2=mean(Age)) %>% arrange(desc(kogus)) %>% filter(kogus>1) reisijad %>% group_by(Country) %>% summarise(kogus=n(), k2=mean(Age), med=median(Age)) %>% arrange(desc(kogus)) %>% filter(kogus>1.5*nrow(reisijad)/100) reisijad %>% mutate(Ag=floor(Age/10)) reisijad %>% mutate(dAge=Age-mean(Age)) reisijad %>% group_by(Country) %>% mutate(dCAge=Age-mean(Age)) reisijad %>% mutate(Ag=floor(Age/10)) %>% group_by(Ag) %>% summarise(kogus=n()) reisijad %>% filter(Country %in% c("Estonia", "Sweden")) %>% mutate(Ag=floor(Age/10)) %>% group_by(Ag, Country) %>% summarise(kogus=n()) reisijad %>% filter(Country %in% c("Estonia", "Sweden", "Latvia")) %>% mutate(Ag=floor(Age/10)) %>% group_by(Ag, Country) %>% summarise(kogus=n()) %>% spread(Country, kogus,fill = 0) reisijad %>% filter(Survived=="1") %>% mutate(Ag=floor(Age/10)) %>% group_by(Ag) %>% summarise(kogus=n()) reisijad %>% mutate(Ag=floor(Age/10)) %>% group_by(Ag) %>% summarise(kogus=n(), elus=sum(Survived), p=elus/kogus) reisijad %>% mutate(Ag=floor(Age/10)) %>% group_by(Ag) %>% summarise(kogus=n(), naisi=sum(Sex=="F"), p=naisi/kogus) reisijad %>% filter(Sex=="F", Age<10) %>% nrow() reisijad %>% filter(Sex=="F") %>% mutate(Ag=floor(Age/10)) %>% group_by(Ag) %>% summarise(kogus=n(), elus=sum(Survived), p=elus/kogus) reisijad %>% filter(Sex=="M") %>% mutate(Ag=floor(Age/10)) %>% group_by(Ag) %>% summarise(kogus=n(), elus=sum(Survived), p=elus/kogus) reisijad %>% mutate(Ag=floor(Age/10)) %>% group_by(Ag, Sex) %>% summarise(kogus=n(), elus=sum(Survived), p=elus/kogus) %>% select(Ag, Sex, p) %>% spread(Sex, p) reisijad %>% filter(Country %in% c("Sweden", "Estonia", "Finland")) %>% mutate(Ag=floor(Age/10)) %>% group_by(Ag, Country) %>% summarise(kogus=n(), elus=sum(Survived), p=elus/kogus) %>% select(Ag, Country, p) %>% spread(Country, p)