英文:
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
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论