ranova

Error 'cannot coerce class ‘"call"’ to a data.frame' in R


Is there a way to turn a call into a vector in R?

I have a call that I got from completing an ANOVA

> final.test.result.type
aov(formula = Value ~ STATION, data = df)

I want to turn the call "final.test.result.type" into a vector that contains a row with the 'call' as a written statement


Solution

  • I would do this:

    1. Create a minimal example (ask me if anything here is an incorrect assumption)
    # fake data
    set.seed(123)
    df <- data.frame(
      Value = rnorm(10),
      STATION = rep(c("A", "B"), each = 5)
    )
    
    # the function
    final.test.result.type <- aov(Value ~ STATION, data = df)
    
    1. Extract the call as a vector
    call_vector <- deparse(final.test.result.type$call)
    

    Note the "[1]" in the output, it is a unidimensional vector

    > call_vector
    [1] "aov(formula = Value ~ STATION, data = df)"