Hello, I have applied the Shapiro test to a matrix with 26.925 rows of data using the following F1.norm<-apply(F1.n.mat,1,shapiro.test) I would now like to view and export a table of the p and W values from the Shapiro test, but I am not sure how to approach this. I have tried the following with errors.> write.table(x=F1.norm,file="I:/R_Work/F1/Shapiro.csv", sep=",") Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors) :cannot coerce class '"htest"' into a data.frame Any suggestions appreciated. Mary AnnĀ F1 F1 [[alternative HTML version deleted]]
I'd loop (possibly but not necessarily with *apply) over F1.norm and get the results directly before returning. E.g., lapply(F1.norm, function(x) c(x$p.value, x$statistic)) Michael On Wed, May 2, 2012 at 1:45 PM, Mary Ann Middleton <maberg at sfu.ca> wrote:> > Hello, > > I have applied the Shapiro test to a matrix with 26.925 rows of data using the following > > F1.norm<-apply(F1.n.mat,1,shapiro.test) > > I would now like to view and export a table of the p and W values from the Shapiro test, but I am not sure how to approach this. > > I have tried the following with errors. >> write.table(x=F1.norm,file="I:/R_Work/F1/Shapiro.csv", sep=",") Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors) : > ?cannot coerce class '"htest"' into a data.frame > > Any suggestions appreciated. > Mary Ann > F1 > F1 > ? ? ? ?[[alternative HTML version deleted]] > > > ______________________________________________ > R-help at r-project.org mailing list > 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. >
Hi Mary Ann,
Use (untested) either
# after creating F1.norm
res <- lapply(F1.norm, function(x) c(statistics = x$statistics, p x$p.value))
write.table(res, ...)
or
# before creating F1.norm
out <- t(apply(F1.n.mat, 1, function(x){
result <- shapiro.test(x)
c(stat = result$statistic, p = result$p.value)
}
))
write.table(out, ...)
instead of what you have.
Regards,
Jorge.-
On Wed, May 2, 2012 at 1:45 PM, Mary Ann Middleton <> wrote:
>
> Hello,
>
> I have applied the Shapiro test to a matrix with 26.925 rows of data using
> the following
>
> F1.norm<-apply(F1.n.mat,1,shapiro.test)
>
> I would now like to view and export a table of the p and W values from the
> Shapiro test, but I am not sure how to approach this.
>
> I have tried the following with errors.
> > write.table(x=F1.norm,file="I:/R_Work/F1/Shapiro.csv",
sep=",") Error in
> as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors >
stringsAsFactors) :
> cannot coerce class '"htest"' into a data.frame
>
> Any suggestions appreciated.
> Mary Ann
> F1
> F1
> [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help@r-project.org mailing list
> 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.
>
>
[[alternative HTML version deleted]]