Next →

Output:


      

Plots:

Data Cleaning and Transformation with dplyr

The dplyr package makes it easy to manipulate and transform data frames in R. Common tasks include filtering rows, selecting columns, creating new variables, and summarizing data.
Unfortunately, we cannot use the dplyr library in our online editor at the moment, but the below code snippets show how this would work.

Example: Filtering and Mutating

library(dplyr)

# Sample data
df <- data.frame(
  name = c("Alice", "Bob", "Charlie", "David"),
  age = c(25, 30, 35, 40),
  score = c(90, 85, 88, 92)
)

# Filter rows where age > 30 and create a new variable "passed"
df_clean <- df %>%
  filter(age > 30) %>%
  mutate(passed = score >= 90)

This pipeline filters the data to only include people older than 30 and adds a new column indicating if their score is above 90.