Created
April 30, 2020 00:54
-
-
Save fuwiak/b5ce4128e177dc5959384dcd895f194b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dplyr) | |
library(sqldf) | |
temp<-sqldf("select * from suicides_tmp") | |
#zmienilem nazwe na total, bo stara nazwa rzucala wyjatki | |
names(temp)[names(temp) == 'suicides.100k.pop_total'] <- 'total' | |
#tutaj mamy podzielony dataframe na kawalki dla kazdego roku oddzielie | |
temp_by_year<-split(temp, temp$year) | |
my_fun<- function(x) { | |
x[order(x$total, decreasing = TRUE),][1:3,] | |
} | |
#wynik:) | |
result<-lapply(temp_by_year, my_fun) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment