How to isolate a factor from a result as a vector?

Asked

Viewed 68 times

1

I want to isolate a factor from the result and leave it as a vector so I can use this factor in another formula.

Example:

library(drc)
data=S.alba
dados$Dose <- as.factor(dados$Dose)
alba.aov <- aov(DryMatter~Dose, data=dados)
summary(alba.aov)

            Df Sum Sq Mean Sq F value Pr(>F)    
Dose         7 121.17  17.310   53.04 <2e-16 ***
Residuals   60  19.58   0.326                   
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

I would like to isolate only the Sum Sq of the Dose. So you could use it in other formulas without having to look for the exact value and changing formula by formula.

Example 2:

SumSqDose <- C(valor do Sum Sq alba.aov)

Instead of writing a formula like this: (121,17/7) It would look something like this: (SumSqDose/7)

Does anyone know how to extract this value without having to look for one by one?

1 answer

5


The exit of summary() is a list object. Among the various options, here are two:

Option 1:

  sm <- summary(alba.aov)

  sm <- unlist(sm)
  names(sm) # para indentificar o que você quer (no seu caso o elemento 3)
  sm[3]

Option 2:

You select the first element of the list, where all information is saved, and use the function str() by identifying all elements of the object:

  sm <- summary(alba.aov)

  str(sm[[1]])
  sm[[1]]$'Sum Sq'[1]

Browser other questions tagged

You are not signed in. Login or sign up in order to post.