Skip to content
Prev 350865 / 398502 Next

help with "by" function

Nilesh,

I found a couple errors in your code.  First, in your by() statement you
have a function to operate on the selected subset of data, which you refer
to as
     x
but then, in your aov statement you refer to
     data_set
not
     x

Second, your funC() statement is a function of
     trait_names
but to make sure that the name of the variable is included in the formula,
I changed this to a character variable.

Give the code below a try and see if it works for you.

Jean


library(agricolae)
library(dplyr)

funC <- function(trait_names){
  by(data_set, data_set$Isopair, function(x) {
  mod <- aov(formula(paste(trait_names, "~ STGgroup*Field +
Rep%in%Field")),
    data=x)
  out <- HSD.test(mod, "STGgroup", group=TRUE, console=TRUE)
  dfout <- arrange(data.frame(out$groups), desc(trt))
  })
}

funC("Trait1")


On Tue, May 12, 2015 at 1:03 PM, DIGHE, NILESH [AG/2362] <
nilesh.dighe at monsanto.com> wrote: