Skip to content

Instantly share code, notes, and snippets.

@fuwiak
Created April 30, 2020 00:54
Show Gist options
  • Save fuwiak/b5ce4128e177dc5959384dcd895f194b to your computer and use it in GitHub Desktop.
Save fuwiak/b5ce4128e177dc5959384dcd895f194b to your computer and use it in GitHub Desktop.
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