-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusing-dplyr.R
More file actions
27 lines (20 loc) · 819 Bytes
/
using-dplyr.R
File metadata and controls
27 lines (20 loc) · 819 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
chicago <- readRDS('chicago.rds')
dim(chicago)
str(chicago)
names(chicago)
subset <- select(chicago, city:date)
head(subset)
chic.f <- filter(chicago,pm25tmean2 > 30)
str(chic.f)
chic.f <- filter(chicago, pm25tmean2 > 30 & tmpd > 80)
select(chic.f, date, tmpd, pm25tmean2)
chicago <- arrange(chicago, date)
head(select(chicago, date, pm25tmean2), 3)
#sorting the dates in descending order
chicago <- arrange(chicago, desc(date))
chicago <- rename(chicago, dewpoint = dptp, pm25 = pm25tmean2)
head(chicago[, 1:5], 3)
#with air pollution data, we often want to detrend the data by subtracting the mean from the data.
chicago <- mutate(chicago, pm25detrend = pm25 - mean(pm25, na.rm = TRUE))
#find information here
#https://bookdown.org/rdpeng/rprogdatascience/managing-data-frames-with-the-dplyr-package.html