Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Easy and thorough description of datasets

NotificationsYou must be signed in to change notification settings

DanChaltiel/crosstable

Repository files navigation

Package-LicenseLifecycle: stableCRAN statusCRAN RStudio mirror downloadsLast CommitCodecov test coverageR-CMD-checkminimal R version

Crosstable is a package centered on a single function,crosstable,which easily computes descriptive statistics on datasets. It can use thetidyverse syntax and is interfaced with the packageofficer tocreate automatized reports.

Installation

# Install last version available on CRANinstall.packages("crosstable")# Install development version on Githubremotes::install_github("DanChaltiel/crosstable@v0.8.2.9002")

Note that, for reproducibility purpose, an even better solution would beto userenv.

Overview

Here are 2 examples to try and show you the main features ofcrosstable. See thedocumentationwebsite for more.

Example #1

Dear crosstable, using themtcars2 dataset, please describe columnsdisp andvs depending on the levels of columnam, with totals inboth rows and columns, and with proportions formatted with group size,percent on row and percent on column, with no decimals.

library(crosstable)ct1= crosstable(mtcars2, c(disp,vs),by=am,total="both",percent_pattern="{n} ({p_row}/{p_col})",percent_digits=0) %>%  as_flextable()ct1

crosstable1

With only a few arguments, we did select which column to describe(c(disp, vs)), define a grouping variable (by=am), set thepercentage calculation in row/column (percent_pattern=), and ask fortotals (total=).

Sincemtcars2 is a dataset with labels, they are displayed instead ofthe variable name (seeherefor how to add some).

Ascrosstable() is returning adata.frame, we useas_flextable()to output a beautiful HTML table. This one can even be exported to MSWord with a few more lines of code (seehereto learn how).

Example #2

Here is a more advanced example.

Dear crosstable, using themtcars2 dataset again, please describeall columns whose name starts with "cy" and those whose name ends with"at", depending on the levels of both columnsam andvs, withoutconsidering labels, applyingmean() andquantile() as summaryfunction, withprobs 25% and 75% defined for this latter function,and with 3 decimals for numeric variables:

ct2= crosstable(mtcars2, c(starts_with("cy"), ends_with("at")),by=c(am,vs),label=FALSE,num_digits=3,funs=c(mean,quantile),funs_arg=list(probs=c(.25,.75))) %>%   as_flextable(compact=TRUE,header_show_n=1:2)ct2

crosstable2

Here, the variables were selected usingtidyselect helpers and thesummary functionsmean andquantile were specified, along withargumentprobs for the latter. Usinglabel=FALSE allowed to seewhich variables were selected but it is best to keep the labels in thefinal table.

Inas_flextable(), thecompact=TRUE option yields a longer output,which may be more suited in some contexts (for instance forpublication), andheader_show_n=1:2 adds the group sizes for both rowsof the header.

Documentation

You can find the whole documentation on thededicatedwebsite:

  • vignette("crosstable") for a first step-by-step guide on how to usecrosstable(link)
  • vignette("crosstable-report") for more on creating MS Word reportsusing either{officer} orRmarkdown(link)
  • vignette("pertent_pattern") for more on how to usepercent_pattern(link)
  • vignette("crosstable-selection") for more on variable selection(link),although you should better readhttps://tidyselect.r-lib.org/articles/syntax.html.

There are lots of other features you can learn about there, for instance(non-exhaustive list):

  • description of correlation, dates, and survival data(link)
  • variable selection with functions, e.g.is.numeric(link)
  • formula interface, allowing to describe more mutated columns,e.g.sqrt(mpg) orSurv(time, event)(link)
  • automatic computation of statistical tests(link)and of effect sizes(link)
  • global options to avoid repeating arguments(link)

Getting help and giving feedback

If you have a question about how to usecrosstable, please ask onStackOverflow with the tagcrosstable.You can@DanChaltiel in a comment if you are struggling to getanswers. Don't forget to add a minimalreproducibleexample toyour question, ideally using thereprexpackage.

If you miss any feature that you think would belong incrosstable,please fill aFeatureRequestissue.

If you encounter an unexpected error while usingcrosstable, pleasefill aBugReportissue. In case of any installation problem, try the solutions proposedinthisarticlefirst.

Acknowledgement

In its earliest development phase,crosstable was based on the awesomepackagebiostat2 written byDavid Hajage. Thanks David!

Packages

No packages published

Contributors8

Languages


[8]ページ先頭

©2009-2025 Movatter.jp