首页 > 解决方案 > 努力过滤R中的数据

问题描述

这是我正在使用的数据:

https://www.dropbox.com/s/dl/chmzqmus6bfoaim/climate_clean.csv

average_temperature_fahrenheit我添加了一个通过这样做调用的变量

climate = mutate(climate, average_temperature_fahrenheit = 9/5*average_temperature_celsius+32)

现在我想知道 1970 年至 1980 年间欧洲和北美 6 月、7 月和 8 月的华氏温度最高,所以我想我需要climate通过这样做来过滤我的数据框

climate %>% filter(continent == c("Europe","North America") & month == c("Jun","Jul","Aug") & year[1970:1980])

但显然我没有成功,因为它只显示了八月

filter请你能告诉我我在功能部分搞砸的地方吗

标签: r

解决方案


你可以和

library(data.table)

climate <-fread("~/downloads/climate_clean.csv")

climate %>%
  mutate(average_temperature_fahrenheit = 9/5*average_temperature_celsius+32) %>%
  filter(year %in% 1970:1980, month %in% c("Jun", "Jul", "Aug")) %>%
  group_by(continent) %>%
  summarise(MaxF = max(average_temperature_fahrenheit))


# A tibble: 6 x 2
  continent      MaxF
  <chr>         <dbl>
1 Africa         93.6
2 Asia           98.6
3 Europe         83.9
4 North America  83.0
5 Oceania        83.7
6 South America  80.2

推荐阅读