Wie kann ich Schleife aov()
Funktion durch alle abhängigen Variablen in das unten stehende Datenmenge:R-Funktion über mehrere Looping varialbles
set.seed(101)
dat <- data.frame(response = rnorm(10, 5, 2),
gender = sample(c(0,1), 10, replace = TRUE),
factorA = sample (c(1:4), 10, replace = TRUE),
factorB = sample(c(letters[1:3]), 10, TRUE)
> dat
response gender factorA factorB
4.347927 1 2 b
6.104924 1 2 b
3.650112 0 1 c
5.428719 1 1 a
5.621538 1 3 b
7.347933 1 4 a
6.237580 0 1 a
4.774531 0 4 c
6.834057 0 1 c
4.553481 1 4 a
Ich möchte und bekommen Speicheraov()
Ausgänge für alle abhängigen Variablen (zB , aov.factorB
) wie eine hergestellt durch:
aov.factorA <- aov(dat$response ~ dat$factorA)
summary(aov.factorA)
die zurückgibt:
Df Sum Sq Mean Sq F value Pr(>F)
dat$factorA 1 0.008 0.0077 0.005 0.945
Residuals 8 12.287 1.5359
So ähnlich? 'res <- lapply (c (" faktorA "," faktorB "), funktion (x) zusammenfassung (aov (dat $ antwort ~ dat [, x]))) ' – zx8754
Genau! Es ergibt die erwartete Ausgabe. – rsl