#Tugas individu
#Mengambil datasets
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ 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("women")
women <- tibble::as.tibble(women)
## 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.
class(women)
## [1] "tbl_df" "tbl" "data.frame"
head(women)
## # A tibble: 6 × 2
## height weight
## <dbl> <dbl>
## 1 58 115
## 2 59 117
## 3 60 120
## 4 61 123
## 5 62 126
## 6 63 129
glimpse(women)
## Rows: 15
## Columns: 2
## $ height <dbl> 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72
## $ weight <dbl> 115, 117, 120, 123, 126, 129, 132, 135, 139, 142, 146, 150, 154…
# Rata-rata berat perempuan
average_weight <- women %>%
summarize(rata_rata_berat = mean(weight))
print(average_weight)
## # A tibble: 1 × 1
## rata_rata_berat
## <dbl>
## 1 137.
# Mengurutkan berat perempuan dari terbesar ke terkecil
Berat <- women %>%
arrange(desc(weight))
print(Berat)
## # A tibble: 15 × 2
## height weight
## <dbl> <dbl>
## 1 72 164
## 2 71 159
## 3 70 154
## 4 69 150
## 5 68 146
## 6 67 142
## 7 66 139
## 8 65 135
## 9 64 132
## 10 63 129
## 11 62 126
## 12 61 123
## 13 60 120
## 14 59 117
## 15 58 115
# Rata-rata tinggi perempuan
average_height <- women %>%
summarize(rata_rata_tinggi = mean(height))
print(average_height)
## # A tibble: 1 × 1
## rata_rata_tinggi
## <dbl>
## 1 65
# Mengurutkan tinggi perempuan dari terbesar ke terkecil
Tinggi <- women %>%
arrange(desc(height))
print(Tinggi)
## # A tibble: 15 × 2
## height weight
## <dbl> <dbl>
## 1 72 164
## 2 71 159
## 3 70 154
## 4 69 150
## 5 68 146
## 6 67 142
## 7 66 139
## 8 65 135
## 9 64 132
## 10 63 129
## 11 62 126
## 12 61 123
## 13 60 120
## 14 59 117
## 15 58 115
Berat <- women %>%
filter(weight > 145)
print(Berat)
## # A tibble: 5 × 2
## height weight
## <dbl> <dbl>
## 1 68 146
## 2 69 150
## 3 70 154
## 4 71 159
## 5 72 164