Quantcast
Channel: Active questions tagged row - Stack Overflow
Viewing all articles
Browse latest Browse all 447

Subset rows using slice_max() - how to use it in R?

$
0
0

I have to create a partial data set containing only the 20 days with the highest daily mean air temperature values for each year. My dataset looks like this:

datemean
1997-07-1527.05292
1997-07-1726.86542
1997-06-2126.10958
1997-07-1626.05833
1997-07-1426.02500
1997-06-2525.80125
1997-07-1825.36208
1997-06-2225.18875
1997-06-2924.72333
1997-06-3024.71000

...

I tried to use the code bellow, but this one only filters the maximum from every year and creates a dataframe with 20 rows - but I need the Top 20 mean values from every year (1997 – 2010). I use the class data.frame btw. I would be so grateful if anyone can help me, I just can't figure it out!

top_20_per_year <- daily_mean_temp_sorted %>%  slice_max(mean, n = 20) %>%

Viewing all articles
Browse latest Browse all 447

Trending Articles