Code aus der Vorlesung

Vorlesung vom 24.04.2026

# ggf. einmalig installieren: 
install.packages("remotes") 
The following package(s) will be installed:
- remotes [2.5.0]
These packages will be installed into "~/RProjects/fhweb/fhweb/renv/library/macos/R-4.5/aarch64-apple-darwin20".

# Installing packages --------------------------------------------------------
- Installing remotes 2.5.0 ...                  OK [linked from cache]
Successfully installed 1 package in 3.1 milliseconds.
remotes::install_github("mchlbckr/MSBStatsData") 
Using GitHub PAT from the git credential store.
Downloading GitHub repo mchlbckr/MSBStatsData@HEAD
rlang    (1.1.7 -> 1.2.0) [CRAN]
glue     (1.8.0 -> 1.8.1) [CRAN]
cli      (3.6.5 -> 3.6.6) [CRAN]
vctrs    (0.7.1 -> 0.7.3) [CRAN]
magrittr (2.0.4 -> 2.0.5) [CRAN]
Installing 5 packages: rlang, glue, cli, vctrs, magrittr
Installing packages into '/Users/michael/RProjects/fhweb/fhweb/renv/library/macos/R-4.5/aarch64-apple-darwin20'
(as 'lib' is unspecified)

The downloaded binary packages are in
    /var/folders/8z/xmqss66n35d8288xh_z6rzhr0000gn/T//RtmpTPqLnA/downloaded_packages
Running `R CMD build`...
* checking for file ‘/private/var/folders/8z/xmqss66n35d8288xh_z6rzhr0000gn/T/RtmpTPqLnA/remotesaa0825a14746/mchlbckr-MSBStatsData-97a5cfc/DESCRIPTION’ ... OK
* preparing ‘MSBStatsData’:
* checking DESCRIPTION meta-information ... OK
* checking for LF line-endings in source and make files and shell scripts
* checking for empty or unneeded directories
* building ‘MSBStatsData_0.1.0.tar.gz’
Installing package into '/Users/michael/RProjects/fhweb/fhweb/renv/library/macos/R-4.5/aarch64-apple-darwin20'
(as 'lib' is unspecified)
library(MSBStatsData) 
cinema_visitors
Warning in base::nchar(wide_chars$test, type = "width"): internal error 1 in
R_decompress1 with libdeflate
Error in `base::nchar()`:
! lazy-load database '/Users/michael/RProjects/fhweb/fhweb/renv/library/macos/R-4.5/aarch64-apple-darwin20/cli/R/sysdata.rdb' is corrupt
company_financials
Warning in base::nchar(wide_chars$test, type = "width"): restarting interrupted
promise evaluation
Warning in base::nchar(wide_chars$test, type = "width"): internal error 1 in
R_decompress1 with libdeflate
Error in `base::nchar()`:
! lazy-load database '/Users/michael/RProjects/fhweb/fhweb/renv/library/macos/R-4.5/aarch64-apple-darwin20/cli/R/sysdata.rdb' is corrupt
# Lagemaße

# install.packages("ggplot2") 
library(ggplot2)

mean(diamonds$price)
[1] 3932.8
hist(diamonds$price)

median(diamonds$price)
[1] 2401
boxplot(diamonds$price, horizontal = TRUE)

mean(diamonds$carat)
[1] 0.7979397
median(diamonds$carat)
[1] 0.7
boxplot(diamonds$carat, horizontal = TRUE)

## Modus
which.max(table(diamonds$carat))
0.3 
 11 
# Aufgabe 4.1

## Varianz
var(cold_rents$monthly_rent_eur)
[1] 13472.22
n <- length(cold_rents$monthly_rent_eur)
var(cold_rents$monthly_rent_eur)*(n-1)/n
[1] 12125

Vorlesung vom 17.04.2026

1+1
[1] 2
log(x = 8, base = 2)
[1] 3
log(8, 2)
[1] 3
log(8)
[1] 2.079442
alter <- 33
name <- "Peter"

name + 1
Error in `name + 1`:
! non-numeric argument to binary operator
alter + 1
[1] 34
## Erstellen eines Vektors mit den Verspätungen
verspaetungen <- c(10, 20, 5, 10, 30, 
                   25, 5, 5, 10, 20, 
                   15, 10, 5, 20, 15, 
                   10, 5, 20, 25, 10)


table(verspaetungen)
verspaetungen
 5 10 15 20 25 30 
 5  6  2  4  2  1 
prop.table(table(verspaetungen))
verspaetungen
   5   10   15   20   25   30 
0.25 0.30 0.10 0.20 0.10 0.05 
# Beschleunigung der Fahrzeuge

## Häufigkeiten
table(mtcars$qsec) # das hier ist die Häufigkeitstabelle

 14.5  14.6 15.41  15.5 15.84 16.46  16.7 16.87  16.9 17.02 17.05  17.3  17.4 
    1     1     1     1     1     1     1     1     1     2     1     1     1 
17.42  17.6 17.82 17.98    18  18.3 18.52  18.6 18.61  18.9 19.44 19.47  19.9 
    1     1     1     1     1     1     1     1     1     2     1     1     1 
   20 20.01 20.22  22.9 
    1     1     1     1 
## Stabiagramm

plot(table(mtcars$qsec), type = "h",
     xlab = "Beschleunigung (Sekunden pro Viertelmeile)",
     ylab = "absolute Häufigkeiten")

## Balkendiagramm

barplot(table(mtcars$qsec),
     xlab = "Beschleunigung (Sekunden pro Viertelmeile)",
     ylab = "absolute Häufigkeiten")

## Histogramm
hist(mtcars$qsec, freq = FALSE)

hist(mtcars$qsec, breaks = 4)

hist(mtcars$qsec, 
     breaks = c(14,15,16,17,18,19,20,24),
     right = FALSE)

## empirische Verteilungsfunktion
plot(ecdf(mtcars$qsec))

library(ggplot2)
hist(diamonds$carat)

plot(ecdf(diamonds$carat))

hist(diamonds$price)

plot(ecdf(diamonds$price))

Zurück nach oben