R Markdown summary

I am trying to print a summary but getting this error message in r markdown

Error in as.data.frame.default(x) : cannot coerce class ‘"summary.prcomp"’ to a data.frame

# summary of each PC
library(knitr)

t2=summary(pca)
t2= kable(t2)

Any advise please?

The result of your summary you put in t2 is not a data.frame. You can't use it inside kable.
Usually, summary results are just some printing step. You can just print them in you document.

If you want a table, you'll need to build your summary result as a table.

or use a package that may help you with that. It seems pander is supporting prcomp class object
https://cran.r-project.org/web/packages/pander/vignettes/pander.html

Or maybe huxtable which uses broom
https://hughjonesd.github.io/huxtable/huxreg.html

Broom helps you get tidy results from model and prcomp is one of them
https://cran.r-project.org/web/packages/broom/vignettes/available-methods.html

Hope it helps.

1 Like

Thank you very much! Using Pander does the trick. Thanks a lot for your help.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.