df %ĭplyr::mutate(df, across(c(condition,gender,student), as.factor)) In this dataset, some of the categorical variables need updating from type numeric to factor. For this to work properly, it is essential that the “type” of the variables is correctly defined. Most of the packages introduced below automatically check the scale level of variables and then compute the appropriate statistic (e.g., frequencies for ordinal data). Select("age","gender","student","condition") To be able to replicate the code and create the table, you can download the sample data from a previous study directly from OSF: url % "officer", # for exporting tables to word "flextable", # for formatting and exporting tables to word "openxlsx", # to save table as Excel file "labelled", # for with labelled variables "sjlabelled", # for working with item labels (retrieving their content) Make sure all required packages are available and loaded: if (!require("pacman")) install.packages("pacman") To see how the Word files look, just click on the package’s name: In what follows, I present a couple of packages that require only little coding, automatically prepare the appropriate statistics, and offer great portability (i.e., save tables as Word or Excel files while keeping as much of the formatting as possible). Another advantage is that the process of creating the tables is automated, transparent, and replicable. Producing tables as Word or Excel files is very convenient when collaborating with others. still others can save tables directly as Word or Excel files others are intended for creating PDF files some only show the results in the console The packages differ in terms of portability: Preparing statistics for different subgroups (e.g., experimental conditions or administrative regions) may entail additional work (see here and here for some tips on how to prepare descriptive tables manually useful functions to prepare multiple summary statistics in one step include rstatix::get_summary_stats, psych::describe, Hmisc::describe, and DescrTab2::descr for ratio and interval data, and janitor::tabyl for nominal and ordinal data).įortunately, there are R packages that facilitate creating such tables. To illustrate, different types of variables require different statistics: Ratio and interval scale variables (e.g., age, test score) are best summarized by their mean and standard deviation, while nominal and ordinal data (e.g., gender, level of education) are better summarized by frequencies and percentages. Gathering and aggregating the relevant information can be tedious. Most reports of empirical work require a table that describes the study sample (e.g., people, animals, organizations).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |