library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.3.2
## Warning: package 'readr' was built under R version 4.3.2
## Warning: package 'dplyr' was built under R version 4.3.2
## Warning: package 'lubridate' was built under R version 4.3.2
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.4 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.0
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(datasets)
library(dplyr)
data("BOD")
BOD <- tibble::as.tibble(BOD)
## Warning: `as.tibble()` was deprecated in tibble 2.0.0.
## ℹ Please use `as_tibble()` instead.
## ℹ The signature and semantics have changed, see `?as_tibble`.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
view(BOD)
head(BOD)
## # A tibble: 6 × 2
## Time demand
## <dbl> <dbl>
## 1 1 8.3
## 2 2 10.3
## 3 3 19
## 4 4 16
## 5 5 15.6
## 6 7 19.8
class(BOD)
## [1] "tbl_df" "tbl" "data.frame"
BOD %>% group_by(Time) %>% summarize(mean=mean(demand))
## # A tibble: 6 × 2
## Time mean
## <dbl> <dbl>
## 1 1 8.3
## 2 2 10.3
## 3 3 19
## 4 4 16
## 5 5 15.6
## 6 7 19.8
BOD %>% arrange(demand)
## # A tibble: 6 × 2
## Time demand
## <dbl> <dbl>
## 1 1 8.3
## 2 2 10.3
## 3 5 15.6
## 4 4 16
## 5 3 19
## 6 7 19.8
BOD %>% arrange(desc(demand))
## # A tibble: 6 × 2
## Time demand
## <dbl> <dbl>
## 1 7 19.8
## 2 3 19
## 3 4 16
## 4 5 15.6
## 5 2 10.3
## 6 1 8.3
BOD %>% filter(demand=="16")
## # A tibble: 1 × 2
## Time demand
## <dbl> <dbl>
## 1 4 16
BOD %>% select(Time)
## # A tibble: 6 × 1
## Time
## <dbl>
## 1 1
## 2 2
## 3 3
## 4 4
## 5 5
## 6 7
BOD %>% select(-Time)
## # A tibble: 6 × 1
## demand
## <dbl>
## 1 8.3
## 2 10.3
## 3 19
## 4 16
## 5 15.6
## 6 19.8
newBOD <- BOD %>% mutate(jumlah= Time+demand)
newBOD
## # A tibble: 6 × 3
## Time demand jumlah
## <dbl> <dbl> <dbl>
## 1 1 8.3 9.3
## 2 2 10.3 12.3
## 3 3 19 22
## 4 4 16 20
## 5 5 15.6 20.6
## 6 7 19.8 26.8