简体   繁体   English

在R中使用table1使用缩写代码指定自定义渲染器

[英]Using abbreviated code to specify a custom renderer using table1 in R

Hello I don't have many experience with R but I need help using abbreviated code to specify a custom renderer for the "table1" package in R. I would like to not display the default stats(FREQ,PCT) variable for categorical data and only display the frequency and omit the percent. 您好,我没有太多的R经验,但是我需要使用缩写代码为R中的“ table1”包指定自定义渲染器的帮助。我不希望为分类数据显示默认stats(FREQ,PCT)变量,仅显示频率并省略百分比。 The code in R Documentations show how to customize this for continuous variables and show some custom statistics for different variables. R文档中的代码显示了如何为连续变量自定义此变量,并显示一些针对不同变量的自定义统计信息。

This is just for the convenience of displaying a frequency table with the built html formatting of package 1. I do know how to get this information otherwise. 这只是为了方便显示带有包1的内置html格式的频率表。我确实知道如何获取此信息。 I am interested learning how to use more this package in R. 我有兴趣学习如何在R中使用更多此程序包。

rndr <- function(x, name, ...)
  {(what <- switch(name,
        c_race = "FREQ",
    parse.abbrev.render.code(c("", what))(x))
}


table1::table1(~c_race|c_ethnicity*c_gender, data = childlearn_demo, 
   render=rndr, overall="Total",topclass="Rtable1-zebra")

The purpose of "abbreviated code" is to allow flexibility without needing to write your own function. “缩写代码”的目的是为了提供灵活性,而无需编写您自己的函数。 Thus, you can get the desired result by simply using render.categorical="Freq" , ie: 因此,您只需使用render.categorical="Freq"即可获得所需的结果,即:

table1::table1(~ c_race|c_ethnicity*c_gender, data = childlearn_demo,
   overall="Total",topclass="Rtable1-zebra", render.categorical="Freq")

(note: I am the table1 package author) (注意:我是table1包的作者)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM