PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, October 7, 2022

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

 October 07, 2022     r, statistics     No comments   

Issue

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?

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 


Answered By - bpvalderrama
Answer Checked By - Clifford M. (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing