0

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.

MrFlick
  • 195,160
  • 17
  • 277
  • 295
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Jul 10 '23 at 15:53

1 Answers1

0

You may try something as below with base R

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

Created on 2023-07-10 with reprex v2.0.2

    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

jkatam
  • 2,691
  • 1
  • 4
  • 12