![]() Pick variables by their names ( select()).Pick observations by their values ( filter()). ![]() In this chapter you are going to learn the five key dplyr functions that allow you to solve the vast majority of your data manipulation challenges: Lgl stands for logical, vectors that contain only TRUE or FALSE.įctr stands for factors, which R uses to represent categorical variables There are three other common types of variables that aren’t used in this dataset but you’ll encounter later in the book: These describe the type of each variable:Ĭhr stands for character vectors, or strings.ĭttm stands for date-times (a date + a time). You might also have noticed the row of three (or four) letter abbreviations under the column names. For now, you don’t need to worry about the differences we’ll come back to tibbles in more detail in wrangle. Tibbles are data frames, but slightly tweaked to work better in the tidyverse. It prints differently because it’s a tibble. (To see the whole dataset, you can run View(flights) which will open the dataset in the RStudio viewer). You might notice that this data frame prints a little differently from other data frames you might have used in the past: it only shows the first few rows and all the columns that fit on one screen. You can override these potentially undesirable defaults in gtsummary. Making an educated guess and only seeing three unique values, gtsummary will treat this as a categorical variable and return frequencies of those values however, you may still want a mean. For example, consider a rating scale with possible values of 1, 2, 3, … 7, but in which respondents only select values of 3, 4, 5. One default I frequently correct is treatment of discrete numeric values. Pay attention to the footnote on the statistical tests performed and adjust if needed with the test argument in the add_p function. In addition, gtsummary makes an educated guess on how to summarize your data and which statistical test to use. Statistical tests performed: Wilcoxon rank-sum test chi-square test of independence Statistics presented: Mean (SD) % (n / N) Note that there is an overall N that corresponds to the number of observations, and each each variable can have its own N that corresponds to the number of non-missing observations for that variable. Here are a few modifications you might be interested in trying to customize your table, including adding an overall column, custom statistic formatting, and table styling. Statistics presented: Median (IQR) n (%)Īnd wait - did you see that?! The raw data had variable names of q12, stheight, and q69 but the table printed the variable label! (I previously tweeted about the awesome package pairing of haven and gtsummary.) If your data does not come with handy labels, you can create them with the label option in tbl_summary or with the var_label function in the labelled package. I’ll demonstrate with the Youth Risk Behavior Surveillance System (YRBSS) data my previous post Leveraging labelled data in R has more background details. My favourite R package for: summarising data by Dabbling with data (2018) How to make beautiful tables in R by R for the Rest of Us (2019). ![]() If you are still searching for your favorite table package, here are two round up resources: The gtsummary documentation is excellent so I won’t cover all of its awesome functionality, but I will add a bit of my specific experience. This blog post is to promote gtsummary and make it more searchable for those still seeking the one table to rule them all. When I showed him gtsummary in 5 minutes, his reaction was all Try it out! BackgroundĪ colleague learning R just told me that he spent 45 minutes searching for a summary table function and couldn’t quite find anything that met his needs. The gtsummary package in R creates amazing publication / presentation / whatever-you-need-it-for ready tables of summary statistics. Figure 1: Happy R adapted from artwork by the beach and cocktail images are from , ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |