Installing libraries

library(tidyverse)
?tidyverse
library(dplyr)

Searching dataset

library(datasets)
library(help="datasets")

Viewing dataset

data(trees)
class(trees)
head(trees)
glimpse(trees)

Filtering data - filter() Filtering trees that has height greater than 65

filtered_trees <- filter(trees, Height > 65)
head(filtered_trees)

Filtering trees that has girth lower than 12

filtered_trees2 <- filter(trees, Girth < 12)
head(filtered_trees2)

Selecting data - select() Selecting Girth Column and Volume Column

trees %>% select(Girth,Volume)

Selecting Height Column and Volume Column

trees %>% select(Height,Volume)

Arranging data - arrange() Arranging Girth from lowest to highest

trees %>% arrange(Girth)

Arranging Height from highest to lowest

trees %>% arrange(desc(Height))

Data Aggregating - summarize() Counting Volume Average for Every Girth Value

trees %>% group_by(Girth) %>% summarize (mean=mean(Volume))

Feature Engineering - mutate() Creating Area Column by dividing Volume and Height

trees_baru <- mutate(trees, Area = Volume / Height)
head(trees_baru)

Using 2 Functions Simultaneously

result1 <- trees %>%
  mutate(Area = Volume / Height) %>%
  select(Girth, Area)
result1

Creating Area Column by dividing Volume and Height. Then, selecting Girth Column and Area Column.

result2 <- trees %>%
  filter(Girth > 10) %>%
  arrange(Height)
result2

Filtering trees that has Girth greater than 10. Then, arranging trees by Height