How to troubleshoot "cannot coerce class ""group"" error to a data.frame"

Asked

Viewed 422 times

1

When rotating the script below, specifically in the part of reproduction of data.frames error was returned:

Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors) : cannot coerce class ""group"" to a data.frame

I looked on the internet and could not reproduce the suggestions for my case, someone shows me a way?

setwd("https://drive.google.com/open?id=1FDMZfWrEjsvleVdNOUiPh8REGjvQHKQx")
rend <- read.table('IVCM.txt', header = TRUE, sep="\t")
rend <- transform(rend, Fungicidas=factor(Fungicidas), Doses=factor(Doses), Rep=factor(Rep))
str(rend)

#---------------------------------------------------------------------------
# desdobrando a interação em testes de Tukey

require(agricolae)
require(plyr)

KinA <- sapply(levels(rend$Doses), simplify=FALSE,
               function(Doses){
                 with(subset(rend, Doses==Doses),
                      HSD.test(IVCM, Fungicidas,
                               DFerror=df.residual(m0),
                               MSerror=deviance(m0)/df.residual(m0)))
               })

KinA <- llply(KinA, NULL)
KinA$M <- gsub(" ", "", KinA$M, fixed=TRUE)
KinA$trt <- as.factor(as.numeric(as.character(KinA$trt)))
str(KinA)

AinK <- sapply(levels(rend$Fungicidas), simplify=FALSE,
               function(Fungicidas){
                 with(subset(rend, Fungicidas==Fungicidas),
                      HSD.test(IVCM, Doses,
                               DFerror=df.residual(m0),
                               MSerror=deviance(m0)/df.residual(m0)))
               })

AinK <- llply(AinK, NULL)
AinK$M <- toupper(gsub(" ", "", AinK$M, fixed=TRUE))
AinK$trt <- as.factor(as.numeric(as.character(AinK$trt)))
str(AinK)

#---------------------------------------------------------------------------
# combinando os data.frames para obter o gráfico e a tabela

KinA$comb <- paste(KinA$trt, KinA$.id)
AinK$comb <- paste(AinK$.id, AinK$trt)
desd <- merge(KinA, AinK, by=c("comb","comb"))
desd$let <- with(desd, paste(M.y, M.x, sep=""))
desd <- desd[,c("trt.x","trt.y","means.x","let")]
names(desd) <- c("Fungicidas","Doses","means","let")
str(desd)
  • Welcome to Stackoverflow! Unfortunately, this question cannot be reproduced by anyone trying to answer it. Please, take a look at this link and see how to ask a reproducible question in R. So, people who wish to help you will be able to do this in the best possible way.

  • The link https://drive.google.com/open?id=1JdgsnJn5VrkL8j1BsfWzqYW9fMGXND6U leads to a table that does not have the columns that are expected by the script. That’s right?

  • Link updated @Danielfalbel. This is the file: https://drive.google.com/open?id=1FDMZfWrEjsvleVdNOUiPh8REGjvQHKQx

  • @Fabianofrança Gives error: Error in deviance(m0) : objeto 'm0' não encontrado.

  • @Fabianofrance Fit a linear model such as m0 <- lm(IVCM ~ Fungicidas + Doses, rend) gives its mistake and the problem is that merge is for class objects "data.frame" so much class(KinA) as class(AinK) sane [1] "list". Besides, I see no reason to run KinA <- llply(KinA, NULL) and the gsub of the following line and the same for llply(AinK, etc).

  • @Noisy was made the model adjustment and checking, which is m0 <- aov(IVCM~Rep+Doses*Fungicidas, data=rend)&#xA;summary(m0)&#xA;par(mfrow=c(2,2)); plot(m0); layout(1). Even so, the error persists.

  • @Fabianofrance Thank you for the reply. But see in my second comment that the main error does not come from the model, but from the values of HSD.test who are in KinA and in AinK, more exactly, the type of data ("list") that HSD.test produces. The function merge unaccepted lists.

  • @Noisy really, thanks for the tips. I’ll try another way to run the statistics. Grateful!

Show 3 more comments
No answers

Browser other questions tagged

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