2  InClass1

Author

Özgenur Şensoy

Published

October 26, 2023

2.0.1 Air Quality

library(dplyr)

Attaching package: 'dplyr'
The following objects are masked from 'package:stats':

    filter, lag
The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union
air_data <- as_tibble(airquality)
head(air_data)
# A tibble: 6 × 6
  Ozone Solar.R  Wind  Temp Month   Day
  <int>   <int> <dbl> <int> <int> <int>
1    41     190   7.4    67     5     1
2    36     118   8      72     5     2
3    12     149  12.6    74     5     3
4    18     313  11.5    62     5     4
5    NA      NA  14.3    56     5     5
6    28      NA  14.9    66     5     6
filtered_data <- air_data %>% filter(Ozone > 31)
print(filtered_data)
# A tibble: 58 × 6
   Ozone Solar.R  Wind  Temp Month   Day
   <int>   <int> <dbl> <int> <int> <int>
 1    41     190   7.4    67     5     1
 2    36     118   8      72     5     2
 3    34     307  12      66     5    17
 4    32      92  12      61     5    24
 5    45     252  14.9    81     5    29
 6   115     223   5.7    79     5    30
 7    37     279   7.4    76     5    31
 8    71     291  13.8    90     6     9
 9    39     323  11.5    87     6    10
10    37     284  20.7    72     6    17
# ℹ 48 more rows
summary_data <- air_data %>%
  summarise(Avg_Ozone = mean(Ozone, na.rm = TRUE))
print(summary_data)
# A tibble: 1 × 1
  Avg_Ozone
      <dbl>
1      42.1
arranged_data <- air_data %>%
  arrange(Wind)
print(arranged_data)
# A tibble: 153 × 6
   Ozone Solar.R  Wind  Temp Month   Day
   <int>   <int> <dbl> <int> <int> <int>
 1    NA      59   1.7    76     6    22
 2   118     225   2.3    94     8    29
 3    73     183   2.8    93     9     3
 4   168     238   3.4    81     8    25
 5   122     255   4      89     8     7
 6   135     269   4.1    84     7     1
 7    NA      91   4.6    76     6    23
 8    64     175   4.6    83     7     5
 9    66      NA   4.6    87     8     6
10    91     189   4.6    93     9     4
# ℹ 143 more rows