PSYC 6136 Tables
rempsyc
Install & load the package
install.packages("rempsyc")
library(rempsyc)
Creating a table using nice_table()
function from the
rempsyc
package
iris
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1 5.1 3.5 1.4 0.2 setosa
2 4.9 3.0 1.4 0.2 setosa
3 4.7 3.2 1.3 0.2 setosa
4 4.6 3.1 1.5 0.2 setosa
5 5.0 3.6 1.4 0.2 setosa
6 5.4 3.9 1.7 0.4 setosa
7 4.6 3.4 1.4 0.3 setosa
8 5.0 3.4 1.5 0.2 setosa
9 4.4 2.9 1.4 0.2 setosa
10 4.9 3.1 1.5 0.1 setosa
11 5.4 3.7 1.5 0.2 setosa
12 4.8 3.4 1.6 0.2 setosa
13 4.8 3.0 1.4 0.1 setosa
14 4.3 3.0 1.1 0.1 setosa
15 5.8 4.0 1.2 0.2 setosa
[ reached 'max' / getOption("max.print") -- omitted 135 rows ]
<- head(iris)
some_iris nice_table(some_iris)
Sepal.Length | Sepal.Width | Petal.Length | Petal.Width | Species |
---|---|---|---|---|
5.10 | 3.50 | 1.40 | 0.20 | setosa |
4.90 | 3.00 | 1.40 | 0.20 | setosa |
4.70 | 3.20 | 1.30 | 0.20 | setosa |
4.60 | 3.10 | 1.50 | 0.20 | setosa |
5.00 | 3.60 | 1.40 | 0.20 | setosa |
5.40 | 3.90 | 1.70 | 0.40 | setosa |
# Using `dplyr` for summary/descriptive statics, i.e., mean and SD
<- iris %>%
desc1 ::group_by(Species) %>%
dplyr::summarise(N=n(),
dplyr'Mean Petal Length'= mean(Petal.Length),
'SD Petal Length'= sd(Petal.Length))
nice_table(desc1, title = "Table 1: Descriptive Statistics Petal Length per Species")
Table 1: Descriptive Statistics Petal Length per Species | |||
---|---|---|---|
Species | N | Mean Petal Length | SD Petal Length |
setosa | 50 | 1.46 | 0.17 |
versicolor | 50 | 4.26 | 0.47 |
virginica | 50 | 5.55 | 0.55 |
Saving as Word doc
You can save you table as a Word doc:
::save_as_docx(desc1, path = "PATH/NAME_OF_FILE.docx") flextable
More Examples
For more info and tutorial, see: https://rempsyc.remi-theriault.com/articles/table
apaTables
Install & load the package
install.packages("apaTables")
library(apaTables)
Creating a table using apa.cor.table()
and
apa.reg.table()
functions from the apaTables
package
# using the iris dataset again:
apa.cor.table(iris)
# or, we could fit a regression model or more
<- lm(Petal.Length~Species, data = iris)
reg.mod1
apa.reg.table(reg.mod1)
# and model comparisons...
<- lm(Petal.Length~Species+Petal.Width, data= iris)
reg.mod2
apa.reg.table(reg.mod1, reg.mod2)
Saving as Word doc
You can save you table as a Word doc:
apa.cor.table(iris,filename="PATH/TABLE EXAMPLE 1.doc")
apa.reg.table(reg.mod1, filename="PATH/TABLE EXAMPLE 2.doc")
More Examples
For more exaples, see: https://mran.microsoft.com/snapshot/2017-06-10/web/packages/apaTables/vignettes/apaTables.html
LS0tCnRpdGxlOiAiUFNZQyA2MTM2IFRhYmxlcyIKYXV0aG9yOiAiVWRpIEFsdGVyIgpkYXRlOiAiYHIgU3lzLkRhdGUoKWAiCm91dHB1dDoKICBybWRmb3JtYXRzOjpyb2JvYm9vazoKICAgIHNlbGZfY29udGFpbmVkOiB0cnVlCiAgICB0aHVtYm5haWxzOiBmYWxzZQogICAgbGlnaHRib3g6IHRydWUKICAgIGdhbGxlcnk6IGZhbHNlCiAgICBjb2RlX2Rvd25sb2FkOiB5ZXMKLS0tCgoKYGBge3Igc2V0dXAsIGVjaG89RkFMU0UsIGNhY2hlPUZBTFNFLCBtZXNzYWdlPUZBTFNFfQpsaWJyYXJ5KGtuaXRyKQpsaWJyYXJ5KHRpZHl2ZXJzZSkKbGlicmFyeShwc3ljaCkKbGlicmFyeShyZWFkcikKbGlicmFyeShjYXIpCmxpYnJhcnkodmNkRXh0cmEpCmxpYnJhcnkoZ3JpZCkKbGlicmFyeShncmlkRXh0cmEpCmxpYnJhcnkodGlkeXZlcnNlKQpsaWJyYXJ5KHJlbXBzeWMpCmxpYnJhcnkoZmxleHRhYmxlKQpsaWJyYXJ5KGFwYVRhYmxl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