gpt4 book ai didi

r - 如何计算在收到阳性结果之前阴性的观察次数

转载 作者:行者123 更新时间:2023-12-01 23:39:11 27 4
gpt4 key购买 nike

我正在处理一些临床数据,我想计算某人在获得“检测到”结果之前“未检测到”的测试数量,并排除从未获得“检测到”结果的任何人。

ID <- c(1,1,2,2,3,3,3,4)
Specimen_Type <- c("NP", "NP", "Throat", "Throat", "NP", "Throat", "Throat", "NP")
RESULT_VAL <- c("Not Detected", "Detected", "Not Detected", "Detected", "Not Detected", "Not Detected", "Detected", "Not Detected")
RESULT_DATE <- c("6-1-2020", "6-10-2020","6-1-2020", "6-10-2020","6-1-2020", "6-10-2020", "6-20-2020", "6-1-2020")
Data_sum<- data.frame(ID, Specimen_Type, RESULT_VAL, RESULT_DATE)

我希望输出看起来像这样(或类似这样的东西),因为我还想看看在阳性结果之前使用了多少种不同的样本类型进行测试。

ID     Number_of_tests_before_pos     Specimen_Type     
1 1 NP
2 1 Throat
3 2 NP,Throat

最佳答案

这是一个基本的 R 选项

transform(
aggregate(
. ~ ID,
cbind(
subset(Data_sum,
ave(RESULT_VAL == "Detected", ID, FUN = function(x) cumsum(x) == 0 & any(x)),
select = c(ID, Specimen_Type)
),
Number_of_tests_before_pos = 1
),
c
),
Number_of_tests_before_pos = lengths(Number_of_tests_before_pos)
)

给予

  ID Specimen_Type Number_of_tests_before_pos
1 1 NP 1
2 2 Throat 1
3 3 NP, Throat 2

关于r - 如何计算在收到阳性结果之前阴性的观察次数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65151598/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com