Fabiano França
2018-Sep-18 02:34 UTC
[R] How to troubleshoot error “cannot coerce class ”“group”“ to a data.frame”?
Dear Volunteers, When running the scriptbelow, specifically in the part of reproduction of the data.framesreturned the error: Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors) : cannot coerce class ""group"" to a data.frame I searched the internet and could not reproduce the suggestions for my case, does anyone tell 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)#---------------------------------------------------------------------------# unfolding the interaction in Tukey tests 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) Many thanks Regards, Fabiano Fran?a da Silva Doutorando em Fitotecnia - ESALQ/USP MSc Fitotecnia - UFLA Eng?. Agr?nomo - UFLA (35) 9 9155-5443 TIM [[alternative HTML version deleted]]
Rui Barradas
2018-Sep-18 10:49 UTC
[R] How to troubleshoot error “cannot coerce class ”“group”“ to a data.frame”?
Hello, This is cross-posted from StackOverflow em Portugu?s [1]. Cross-posting is not well seen and you should wait for a while for an answer given where you have you original question before posting somewhere else. [1] https://pt.stackoverflow.com/questions/330200/como-solucionar-erro-cannot-coerce-class-group-to-a-data-frame Note: I will try to answer to it, if I have the time, in SOpt. This does not mean that you will not get other answers, for instance in R-Help. Rui Barradas ?s 03:34 de 18/09/2018, Fabiano Fran?a escreveu:> Dear Volunteers, > When running the scriptbelow, specifically in the part of reproduction of the data.framesreturned the error: > > Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors) : cannot coerce class ""group"" to a data.frame > > I searched the internet and could not reproduce the suggestions for my case, does anyone tell 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)#---------------------------------------------------------------------------# unfolding the interaction in Tukey tests > > 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) > > Many thanks > > Regards, > > Fabiano Fran?a da Silva > Doutorando em Fitotecnia - ESALQ/USP > MSc Fitotecnia - UFLA > Eng?. Agr?nomo - UFLA > (35) 9 9155-5443 TIM > > > > [[alternative HTML version deleted]] > > > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >