do.call(sqrt,4) do.call(sqrt,list(4)) pi |> sqrt pi |> sqrt() l1 = seq(0,2*pi,length=100) l1.length l1.length() l1$length l1 length(l1) plot(l1,) sin = sin(x) sin = sin(l1) plot(x,sin, type="l") plot(l1,sin, type="l") carsten = sin(l1) plot(carsten,sin, type="l") plot(l1,carsten, type="l") ?rep # Ihre Lösung data.frame(seq(0:10)) # Ihre Lösung data.frame(seq(0:10), seq(3,4)) # Ihre Lösung data.frame(seq(0:10), seq(0:10)) wort = rep("Wort",100) data.frame(zahl,wort) df.head() df <- data.frame(zahl,wort) # Ihre Lösung zahl <- seq(5,25,length=100) hl <- seq(5,25,length=100) wort <- rep("Wort",100) df <- data.frame(zahl,wort) df.head() head(df) head(df,10) res = df[[67]] res = df df res = df$zahl res res = df$zahl[[67]] res print(round(res,2)) # Ihre Lösung: M set.seed(12) # Zufallszahlengenerator gleich machen. M = matrix(sample(c(1, 2, 3), 10 * 100, T), nrow = 100) # Ihre Lösung: M ?apply # Ihre Lösung: apply(M,sum) ```{r} # Ihre Lösung: apply(M,M[:,2],sum) # Ihre Lösung: apply(M,M[1],sum) # Ihre Lösung: apply(M,M[2],sum) # Ihre Lösung: apply(M,M[3],sum) # Ihre Lösung: apply(M,M[1],sum) # Ihre Lösung: apply(M,M[2],sum) # Ihre Lösung: apply(M,M[2],sum) # Ihre Lösung: apply(M,M[1],sum) # Ihre Lösung: apply(M,M[1],sum) # Ihre Lösung: apply(M,c(1,2),sum) apply(M,c(1,2),sum) apply(M,2,sum) k = M[:,5] k = M[,5] k length(k) sum(k) k = M[,1] k set.seed(12) # Zufallszahlengenerator gleich machen. M = matrix(sample(c(1, 2, 3), 10 * 100, T), nrow = 100) # Ihre Lösung: apply(M,2,sum) k = M[,1] sum(k) apply(M,2,sqrt) 0 set.seed(12) # Zufallszahlengenerator gleich machen. M = matrix(sample(c(1, 2, 3), 10 * 100, T), nrow = 100) # Ihre Lösung: count_2 = function(a){ if (a == 2){ return 1 1 set.seed(12) # Zufallszahlengenerator gleich machen. M = matrix(sample(c(1, 2, 3), 10 * 100, T), nrow = 100) # Ihre Lösung: count_2 = function(a){ if (a == 2){ 1 } 0 } apply(M,2,sum) apply(M,2,count_2) ?sqrt count_2(3) count_2(2) 0 set.seed(12) # Zufallszahlengenerator gleich machen. M = matrix(sample(c(1, 2, 3), 10 * 100, T), nrow = 100) # Ihre Lösung: count_2 = function(a){ if (a == 2){ 1 } else{ 0 } } apply(M,2,count_2) count_2(2) ?apply ```{r} 0 ?all set.seed(12) # Zufallszahlengenerator gleich machen. M = matrix(sample(c(1, 2, 3), 10 * 100, T), nrow = 100) # Ihre Lösung: count_2 <- function(a){ print(typeof(a)) } apply(M,2,count_2) count_2(2) set.seed(12) # Zufallszahlengenerator gleich machen. M = matrix(sample(c(1, 2, 3), 10 * 100, T), nrow = 100) # Ihre Lösung: count_2 <- function(a){ print(typeof(a)) print(length(a)) } apply(M,2,count_2) count_2(2) apply(M,2,count_2) sum(a) set.seed(12) # Zufallszahlengenerator gleich machen. M = matrix(sample(c(1, 2, 3), 10 * 100, T), nrow = 100) # Ihre Lösung: count_2 <- function(a){ sum(a) } apply(M,2,count_2) a[[a==2]] set.seed(12) # Zufallszahlengenerator gleich machen. M = matrix(sample(c(1, 2, 3), 10 * 100, T), nrow = 100) # Ihre Lösung: count_2 <- function(a){ a[[a==2]] } apply(M,2,count_2) set.seed(12) # Zufallszahlengenerator gleich machen. M = matrix(sample(c(1, 2, 3), 10 * 100, T), nrow = 100) # Ihre Lösung: count_2 <- function(a){ a } apply(M,2,count_2) set.seed(12) # Zufallszahlengenerator gleich machen. M = matrix(sample(c(1, 2, 3), 10 * 100, T), nrow = 100) # Ihre Lösung: count_2 <- function(a){ a } res = apply(M,2,count_2) res ?sum ?count a==2 set.seed(12) # Zufallszahlengenerator gleich machen. M = matrix(sample(c(1, 2, 3), 10 * 100, T), nrow = 100) # Ihre Lösung: count_2 <- function(a){ a==2 } res = apply(M,2,count_2) res num_2 = apply(M,2,sum) set.seed(12) # Zufallszahlengenerator gleich machen. M = matrix(sample(c(1, 2, 3), 10 * 100, T), nrow = 100) # Ihre Lösung: count_2 <- function(a){ a==2 } res = apply(M,2,count_2) num_2 = apply(M,2,sum) num_2 set.seed(12) # Zufallszahlengenerator gleich machen. M = matrix(sample(c(1, 2, 3), 10 * 100, T), nrow = 100) # Ihre Lösung: count_2 <- function(a){ a==2 } res = apply(M,2,count_2) num_2 = apply(res,2,sum) num_2 2_in_r5 = num2[[5]] set.seed(12) # Zufallszahlengenerator gleich machen. M = matrix(sample(c(1, 2, 3), 10 * 100, T), nrow = 100) # Ihre Lösung: count_2 <- function(a){ a==2 } res = apply(M,2,count_2) num_2 = apply(res,2,sum) 2in_r5 = num2[[5]] set.seed(12) # Zufallszahlengenerator gleich machen. M = matrix(sample(c(1, 2, 3), 10 * 100, T), nrow = 100) # Ihre Lösung: count_2 <- function(a){ a==2 } res = apply(M,2,count_2) num_2 = apply(res,2,sum) two_in_r5 = num2[[5]] set.seed(12) # Zufallszahlengenerator gleich machen. M = matrix(sample(c(1, 2, 3), 10 * 100, T), nrow = 100) # Ihre Lösung: count_2 <- function(a){ a==2 } res = apply(M,2,count_2) num_2 = apply(res,2,sum) two_in_r5 = num_2[[5]] set.seed(12) # Zufallszahlengenerator gleich machen. M = matrix(sample(c(1, 2, 3), 10 * 100, T), nrow = 100) # Ihre Lösung: count_2 <- function(a){ a==2 } res = apply(M,2,count_2) z = apply(res,2,sum) two_in_r5 = z[[5]] print("Es gibt {two_in_r5} ") set.seed(12) # Zufallszahlengenerator gleich machen. M = matrix(sample(c(1, 2, 3), 10 * 100, T), nrow = 100) # Ihre Lösung: count_2 <- function(a){ a==2 } res = apply(M,2,count_2) z = apply(res,2,sum) two_in_r5 = z[[5]] print(paste0("Es gibt", two_in_r5) set.seed(12) # Zufallszahlengenerator gleich machen. M = matrix(sample(c(1, 2, 3), 10 * 100, T), nrow = 100) # Ihre Lösung: count_2 <- function(a){ a==2 } res = apply(M,2,count_2) z = apply(res,2,sum) two_in_r5 = z[[5]] print(paste0("Es gibt", two_in_r5)) set.seed(12) # Zufallszahlengenerator gleich machen. M = matrix(sample(c(1, 2, 3), 10 * 100, T), nrow = 100) # Ihre Lösung: count_2 <- function(a){ a==2 } res = apply(M,2,count_2) z = apply(res,2,sum) two_in_r5 = z[[5]] print(paste0("Es gibt ", two_in_r5, " in Spalte 5")) set.seed(12) # Zufallszahlengenerator gleich machen. M = matrix(sample(c(1, 2, 3), 10 * 100, T), nrow = 100) # Ihre Lösung: count_2 <- function(a){ a==2 } res = apply(M,2,count_2) z = apply(res,2,sum) two_in_r5 = z[[5]] print(paste0("Es gibt ", two_in_r5, " 2er in Spalte 5")) set.seed(12) # Zufallszahlengenerator gleich machen. M = matrix(sample(c(1, 2, 3), 10 * 100, T), nrow = 100) # Ihre Lösung: count_2 <- function(a){ sum(a==2) } res = apply(M,2,count_2) z = apply(res,2,sum) res set.seed(12) # Zufallszahlengenerator gleich machen. M = matrix(sample(c(1, 2, 3), 10 * 100, T), nrow = 100) # Ihre Lösung: count_2 <- function(a){ sum(a==2) } z = apply(M,2,count_2) print(paste0("Es gibt ", z[[5]], " 2er in Spalte 5")) seq(1, 10, length.out = 20) length(seq(1, 10, length.out = 20)) r = seq(1, 10, length = 20) r r = seq(1, 10, by=0.5) r r = seq(0, 10, length = 20) r r = seq(1, 10, length = 21) r r = seq(0, 10, length.out = 20) r r = seq(0, 10, length.out = 10) r r = seq(1, 10, length.out = 10) r r = seq(1, 10, length.out = 20) r setwd("~/Documents/Masterstudium/1.Semester/DSR") git pulll clear() if (min >= max) { stop("min muss kleiner als max sein.") } # Bitte mit echter Lösung in myhistogram.R ersetzen: myhistogram = function(x, n, min, max) { if (missing(min)) min <- base::min(x) if (missing(max)) max <- base::max(x) if (missing(n)) n <- 10 if (min >= max) { stop("min muss kleiner als max sein.") } range <- min + max interval_ranges <- (max - min) / n borders <- seq(min, max, length.out = n + 1) counts <- rep(0, n) for(value in x) { for (i in 1:n){ if (value >= borders[i] && value < borders[i+1]){ counts[i] <- counts[i] + 1 break } } } print(paste("Intervallgrößen: ", interval_ranges)) list(borders=borders, counts = counts) } x = seq(-5, 6, by = 1 / 3) l = myhistogram(x) print(l$borders) print(l$counts) setwd("~/Documents/Masterstudium/1.Semester/DSR_Testate") # Bitte mit echter Lösung in myhistogram.R ersetzen: myhistogram = function(x, n, min, max) { if (missing(min)) min <- base::min(x) if (missing(max)) max <- base::max(x) if (missing(n)) n <- 10 if (min >= max) { stop("min muss kleiner als max sein.") } range <- min + max interval_ranges <- (max - min) / n borders <- seq(min, max, length.out = n + 1) counts <- rep(0, n) for(value in x) { for (i in 1:n){ if (value >= borders[i] && value < borders[i+1]){ counts[i] <- counts[i] + 1 break } } } print(paste("Intervallgrößen: ", interval_ranges)) list(borders=borders, counts = counts) } x = seq(-5, 6, by = 1 / 3) l = myhistogram(x) print(l$borders) print(l$counts) x = seq(-5, 6, by = 1 / 3) l = myhistogram(x, n = 10, min = -5, max = 6) solution = list( borders = c(-5.0, -3.9, -2.8, -1.7, -0.6, 0.5, 1.6, 2.7, 3.8, 4.9, 6.0), counts = c(4, 3, 3, 4, 3, 3, 4, 3, 3, 3) ) print(l$borders) print(l$counts) set.seed(1) x = rnorm(0, 1, n = 1000) # h = myhistogram(x, n = 20) # ggplot() + ... # Bitte mit echter Lösung in myhistogram.R ersetzen: myhistogram = function(x, n, min, max) { if (missing(min)) min <- base::min(x) if (missing(max)) max <- base::max(x) if (missing(n)) n <- 10 if (min >= max) { stop("min muss kleiner als max sein.") } range <- min + max interval_ranges <- (max - min) / n borders <- seq(min, max, length.out = n + 1) counts <- rep(0, n) for(value in x) { for (i in 1:n){ if (value >= borders[i] && value < borders[i+1]){ counts[i] <- counts[i] + 1 break } } } print(paste("Intervallgrößen: ", interval_ranges)) list(borders=borders, counts = counts) } x = seq(-5, 6, by = 1 / 3) l = myhistogram(x) print(l$borders) print(l$counts)