The following is a script file containing all R code of all sections in this slide set.
library(dplyr)
data(iris)
ir <- as_tibble(iris)
ir
library(dplyr)
dbConn <- DBI::dbConnect(RMariaDB::MariaDB(),
dbname="myDatabase"
host="myorganization.com",
user="myUser",
password=rstudioapi::askForPassword("DB password"))
sensors <- tbl(dbConn,"sensor_values")
filter(ir,Sepal.Length > 6,Sepal.Width > 3.5)
filter(ir,Sepal.Length > 7.7 | Sepal.Length < 4.4)
arrange(ir,Species,Petal.Width)
arrange(ir,desc(Sepal.Width),Petal.Length)
select(ir,Sepal.Length,Species)
select(ir,-(Sepal.Length:Sepal.Width))
select(ir,starts_with("Sepal"))
mutate(ir,sr=Sepal.Length/Sepal.Width,pr=Petal.Length/Petal.Width,rat=sr/pr)
select(filter(ir,Petal.Width > 2.3),Sepal.Length,Species)
arrange(
select(
filter(
mutate(ir,sr=Sepal.Length/Sepal.Width),
sr > 1.6),
Sepal.Length,Species),
Species,desc(Sepal.Length))
mutate(ir,sr=Sepal.Length/Sepal.Width) %>% filter(sr > 1.6) %>%
select(Sepal.Length,Species) %>% arrange(Species,desc(Sepal.Length))
summarise(ir,avgPL= mean(Petal.Length),varSW = var(Sepal.Width))
sps <- group_by(ir,Species)
sps
group_by(ir,Species) %>% summarise(mPL=mean(Petal.Length))
group_by(ir,Species) %>% tally()
group_by(ir,Species) %>% summarise(n=n())
count(ir,Species)
group_by(ir,Species) %>% arrange(desc(Petal.Length)) %>% slice(1:2)
group_by(ir,Species) %>% top_n(2,Petal.Length) # note the slight difference!
group_by(ir,Species) %>% arrange(Sepal.Width) %>% slice(1:2)
group_by(ir,Species) %>% top_n(-2,Sepal.Width) # note the slight difference!