Exercises – Markdown (Introduction to R)
Task 1
- Using
mtcars, select all cars with
- more than 6 cylinders (
cyl > 6) and
- mileage below 20 (
mpg < 20).
Task 2
- Using
mtcars, sort the cars by
- descending horsepower (
hp), and
- ascending weight (
wt).
Task 3
- From
mtcars, select only the variablesmpg,cyl,hp, andwt.
Task 4
- Using
mtcars, create a new variablepower_to_weight = hp / wt.
Task 5
- Using
mtcars, compute per number of cylinders (cyl)
- the mean mileage (
mpg), and
- the number of cars.
Task 6
Write a single dplyr pipeline that
- keeps only cars with automatic transmission (
am == 0),
- groups the data by
cyl,
- computes the mean horsepower (
hp),
- arranges the result by descending mean horsepower.
Task 7
- Using
starwars, select all characters who
- are human, and
- have a known height.
- Keep only the variables
name,height, andmass.
- Store the result in
human_characters.
Task 8
- Using
starwars, create a new variablebmi = mass / (height / 100)^2
- Ignore rows with missing
heightormass.
- Store the result in
starwars_bmi.
Task 9
- Using
starwars, compute per species
- the mean height, and
- the number of characters.
- Remove species with fewer than 3 characters.
Task 10
Write a single dplyr pipeline that
- keeps only characters with known
genderandmass,
- groups the data by
gender,
- computes the median mass per gender,
- keeps only genders with a median mass above the overall median mass,
- returns a tidy summary table.
- Store the result in
gender_mass_summary.