5  Lösungen Dinojudo

5.1 Lösung 1

# Aufgabe 1 

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.5.1     ✔ tibble    3.2.1
✔ lubridate 1.9.3     ✔ tidyr     1.3.1
✔ 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
#1.1
library(readr)
Jurassic_Park <- read_csv("https://raw.githubusercontent.com/raphaelbalzer/Tutorium_QM1_SoSe23/main/Jurassic_Park.csv")
New names:
Rows: 291 Columns: 11
── Column specification
──────────────────────────────────────────────────────── Delimiter: "," chr
(9): name, diet, period, lived_in, type, taxonomy, named_by, species, link dbl
(2): ...1, Length
ℹ Use `spec()` to retrieve the full column specification for this data. ℹ
Specify the column types or set `show_col_types = FALSE` to quiet this message.
• `` -> `...1`
#1.2
head(Jurassic_Park, n = 10)
#1.3
tail(Jurassic_Park, n = 10)

5.2 Lösung 2

# Aufgabe 2

#2.1
Jurassic_Park2 <- Jurassic_Park %>% 
  select(name, diet,lived_in,type,Length, species, named_by)

#2.2
Jurassic_Park2 %>% 
  arrange(-Length) -> Jurassic_Park2

#2.3
Jurassic_Park2 %>% 
  count(Length > 7.5)

5.3 Lösung 3

# Aufgabe 3

#3.1
Jurassic_Park %>% 
  summarise(mean(Length))
#3.2
Jurassic_Park %>% 
  count(diet)
#3.3
Jurassic_Park2 %>% 
  select(named_by, name) %>% 
  filter(name == "gobisaurus")

5.4 Lösung 4

#4.1
Jurassic_Park %>% 
  group_by(diet) %>% 
  summarise(mean(Length))
#4.2
Jurassic_Park %>% 
  select(type, lived_in) %>% 
  filter(type == "armoured dinosaur") %>% 
  count(lived_in)
#4.3
Jurassic_Park %>% 
  select(Length, type) %>% 
  filter(type == "small theropod") %>% 
  arrange(Length)
#4.4
Jurassic_Park %>% 
  select(diet, lived_in) %>%
  filter(lived_in == "USA") %>% 
  count(diet)

5.5 Lösung 5

# Dino1
Jurassic_Park %>% 
  select(type, diet, lived_in, Length) %>% 
  filter(lived_in == "North Africa",
         type == "large theropod",
         diet == "carnivorous") %>%
  summarise(mean(Length))
# Dino2
Jurassic_Park %>% 
  select(type, diet, lived_in, Length) %>% 
  filter(lived_in == "China",
         type == "sauropod",
         diet == "herbivorous") %>%
  summarise(mean(Length))