Skip to content

Commit

Permalink
assignment solutions
Browse files Browse the repository at this point in the history
  • Loading branch information
Ludwigm6 committed Oct 31, 2024
1 parent 2d49e9c commit eec8008
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 65 deletions.
63 changes: 2 additions & 61 deletions assignments/Ex04a_trees.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
## ----------------------------------------------------------------------------------------------------------------------------------------------------------


districts = read.csv("data/muenster_districts.csv")
trees = read.csv("data/muenster_trees.csv")



#'
#'
Expand All @@ -22,8 +18,6 @@ trees = read.csv("data/muenster_trees.csv")
#'
## ----------------------------------------------------------------------------------------------------------------------------------------------------------

head(trees)
str(districts)


#'
Expand All @@ -35,11 +29,6 @@ str(districts)
#'
## ----------------------------------------------------------------------------------------------------------------------------------------------------------

table(districts$district_group)

table(districts$district_group, districts$district)

unique(districts$district_group)


#'
Expand All @@ -50,33 +39,12 @@ unique(districts$district_group)
#'
## ----------------------------------------------------------------------------------------------------------------------------------------------------------

districts[districts$area == max(districts$area), ]

districts[districts$area == max(districts$area), ]$district

districts[districts$area == max(districts$area), "district"]

districts$district[districts$area == max(districts$area)]


library(tidyverse)
districts |> filter(area == max(districts$area)) |> select(district)

#'
#' - Wie groß ist die Bezirksgruppe "Altstadt"?
#'
## ----------------------------------------------------------------------------------------------------------------------------------------------------------

sum(districts[districts$district_group == "Altstadt",]$area)

length(districts[districts$district_group == "Altstadt",]$area)


districts |>
filter(district_group == "Altstadt") |>
select(area) |>
sum()


#'
#'
Expand All @@ -103,7 +71,7 @@ districts |>
#'
## ----------------------------------------------------------------------------------------------------------------------------------------------------------

length(unique(trees$species))



#'
Expand All @@ -112,7 +80,7 @@ length(unique(trees$species))
## ----------------------------------------------------------------------------------------------------------------------------------------------------------


sum(trees$species == "Fagus")



#'
Expand All @@ -121,16 +89,6 @@ sum(trees$species == "Fagus")
#'
## ----------------------------------------------------------------------------------------------------------------------------------------------------------

which.max(table(trees$district))

sort(table(trees$district), decreasing = TRUE)[1]



test = data.frame(col1 = c("a", "a", "a", "b", "b", "b", "c", "c"))

which.max(table(test$col1))
table(test$col1)[table(test$col1) == max(table(test$col1))]


#'
Expand All @@ -140,14 +98,6 @@ table(test$col1)[table(test$col1) == max(table(test$col1))]
## ----------------------------------------------------------------------------------------------------------------------------------------------------------


which.max(table(trees$district[trees$species == "Magnolia"]))


trees |>
filter(species == "Magnolia") |>
select(district) |>
table() |>
which.max()

#'
#'
Expand All @@ -158,15 +108,6 @@ trees |>
## ----------------------------------------------------------------------------------------------------------------------------------------------------------


district_central = districts[districts$district_group == "Altstadt" | districts$district_group == "Innenstadtring",]$district

# andere schreibweise
district_central = districts[districts$district_group %in% c("Altstadt", "Innenstadtring"),]$district

# baume aus den bezirken filtern
trees_central = trees[is.element(trees$district, district_central),]
trees_central = trees[trees$district %in% district_central,]

plot(trees_central$X, trees_central$Y, asp = 1, cex = 0.1)


4 changes: 0 additions & 4 deletions assignments/Ex04b_trees_tidyverse.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@
## ----------------------------------------------------------------------------------------------------------------------------------------------------------


trees |> group_by(district) |>
summarise(length(unique(species)))





0 comments on commit eec8008

Please sign in to comment.