-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpipes.R
35 lines (25 loc) · 869 Bytes
/
pipes.R
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
28
29
30
31
32
33
34
35
#pipes
#is a tool in R for expressing a sequence of multiple
#operations represented by "%>%"
#it takes the output of one statement and makes it
#the input of another statement
#importing data set
data("ToothGrowth")
View(ToothGrowth)
library("dplyr")
filtered_tg<- filter(ToothGrowth, dose==0.5)
arrange(filtered_tg,len)
#instead we can use nested function to save our lines of code
arrange(filter(ToothGrowth, dose==0.5),len)
# now we'll use a pipe to do our job
#tip;press ctrl+shift+m to get pipe operator
filtered_tgpipe <- ToothGrowth %>%
filter(dose==0.5) %>%
arrange(len)
# finding mean length from both supplements
#orange juice oj and ascorbic acid vc
filtered_pipe <- ToothGrowth %>%
filter(dose==0.5) %>%
group_by(supp) %>%
summarise(mean_len= mean(len, na.rm=T), .group="drop")
View(filtered_pipe)