有没有办法将数据帧的不同子集用于R中table1中的不同变量

问题描述 投票:0回答:1

我正在制作健康变量的汇总表。有一些条件变量仅在选择另一个变量的值时进行观察:如果患者对是否接受了呼吸支持回答“是”,则具有呼吸支持类型的因素变量。

我正在使用 table1 包:https://cran.r-project.org/package=table1

我的问题是,使用“table1”生成的单个表格将给出呼吸支持类型的缺失数据的错误数量,因为它包括对“是否接受过呼吸支持”也回答“否”的患者。

我想知道是否可以总结那些在 table1 函数中只回答“是”的人的数据。 例如数据集是这样的:

data.frame(received_resp_support = c("no", "yes", "yes", "yes"), type_resp_support = factor(c(NA, "A", "B", NA)))

第一个 NA 是因为个人没有获得支持,第二个 NA 是真正的缺失数据。在表 1 中,使用此数据框,根据上述内容,对于缺失的数据行 
当它应该是一个时

有两个观察值。 library(table1) table1(~received_resp_support+type_resp_support, data=a)

enter image description here

r
1个回答
0
投票
type_resp_support

函数中使用

table1()
作为分层变量。但是,不允许有缺失值 (
NA
)。但你可以用例如替换
NA
数据框中的
Missing
它看起来像这样:

a=data.frame(received_resp_support = c("no", "yes", "yes", "yes"), type_resp_support = factor(c("Missing", "A", "B", "Missing")))

table1(~received_resp_support | type_resp_support, data=a)

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.