Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I find the proportion of a value in a variable on R?

I want to find how many people who were surveyed for HIV tested negative.

I have an objective titled as HIV. Where HIV=0 is people who are negative. HIV=1, 2, 3, 4 are different levels of viral load of all people who tested positive.

I want to know of all people who are under the HIV objective, how many have HIV = 0?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I especially want to know how to calculate this value when there are missing values. TIA.

>Solution :

Assuming your data is a vector called HIV:

HIV <- rep(c(0, 1, 2, 3, 4, NA), each = 4)

Which looks like this:

 [1]  0  0  0  0  1  1  1  1  2  2  2  2  3  3  3  3  4  4  4  4 NA NA NA NA

You can use the following:

prop.table(table(Data)))

To get an table object like this:

HIV
  0   1   2   3   4 
0.2 0.2 0.2 0.2 0.2 
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading