extract multiple values based on other column [duplicate]
We may use subset
for this.
# option 1
aov(Faktor ~ total_Sum, data = subset(FSQ, Faktor %in% c(0,2)))
# option 2
with(subset(FSQ, Faktor %in% c(0,2)), aov(Faktor ~ total_Sum))
Output
Call:
aov(formula = Faktor ~ total_Sum)
Terms:
total_Sum Residuals
Sum of Squares 0 8
Deg. of Freedom 1 6
Residual standard error: 1.154701
Estimated effects may be unbalanced
Data
FSQ <- data.frame(
Faktor = rep(c(0,1,2), 4L),
total_Sum = c(4,23,4,0,0,0,3,3,7,4,0,0)
)
You could create a new dataframe containing only rows where Faktor equals 0 or 2:
newFSQ <- FSQ[Faktor == 0 | Faktor == 2,]
aov(newFSQ$Faktor ~ newFSQ$total_Sum)