尝试将种族和族裔类别结合起来,以了解更多关于患者的信息。

huangapple go评论69阅读模式
英文:

Trying to combine race and ethnicity categories to find out more about patient

问题

我有一个数据框,第一列是患者的ID,第二列表示他们的种族,用数字1-6表示,第四列是他们的族裔,无论是西班牙裔/拉丁裔、非西班牙裔/拉丁裔还是其他。我想找出哪些患者是白人西班牙裔/拉丁裔、白人非西班牙裔/拉丁裔、黑人西班牙裔/拉丁裔、黑人其他等。我应该如何做呢?

这只是我的表格的一个小示例。"Specify"列还包括其他族裔,如菲律宾人、洪都拉斯人等。我相信在R中有一个函数,我可以使用表格函数来交叉比较两个变量,但我不知道是否正确。我想要一个显示每个患者及其种族和族裔的表格。

英文:

I have a data frame with the first column being patient IDS, second column stating which race they are with numbers 1-6, and the 4th column being ethnicity whether they are Hispanic/Latino, Not Hispanic/Latino, or Other. I want to find out which patients are White Hispanic/Latino, White Not Hispanic/Latino, Black Hispanic/Latino, Black Other, etc. How would I go about doing that

enter image description here

This just a small example of how my table looks like. The "Specify" column also includes other ethnicities like Filipino, Honduran, etc. I believe there is a function in R where I can cross compare two variables with the table function but I do not know if that would be right. I would want a table that displays each patient and their race and ethnicity.

答案1

得分: 1

# 你可以尝试以下使用 'base R' 的代码

table(adsl$SUBJID, adsl$RACEN, adsl$ETHNIC) %>% as.data.frame() %>% subset(Freq > 0)
英文:

You may try something as below with base R

table(adsl$SUBJID,adsl$RACEN,adsl$ETHNIC) %>% as.data.frame() %>% subset(Freq>0)

<sup>Created on 2023-07-10 with reprex v2.0.2</sup>

    Var1 Var2               Var3 Freq
10  1015    1 HISPANIC OR LATINO    1
16  1023    1 HISPANIC OR LATINO    1
24  1031    1 HISPANIC OR LATINO    1
94  1154    1 HISPANIC OR LATINO    1
137 1235    1 HISPANIC OR LATINO    1
140 1239    1 HISPANIC OR LATINO    1

huangapple
  • 本文由 发表于 2023年7月10日 23:44:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/76655336.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定