R Practicals

Categories:

Recommended

The best way to start getting comfortable with a new language is to use it. This series of exercises reviews some of the content we’ve discussed during lecture and introduces some other basic concepts about working with data in R. It’s important that you actively type in the commands and review the results rather than just read. Try to briefly answer the questions that come up along the way. Don’t worry if everything doesn’t make a lot of sense during the earlier exercises. It will. And there’s an answer key available if you become too frustrated.

Start R and open a new script document. The approach may differ in minor details depending on whether you are on a Windows or Mac machine.

1.1 working with objects

1.1.1 vectors

A vector is one of the most basic R objects, and a good place to start using R for epidemiology. Consider the following epidemiologic scenario taken from Tomas Aragon’s book “Applied Epidemiology Using R”. In 2003, 111 airplane passengers were exposed to a fellow passenger who was subsequently diagnosed with Severe Acute Respiratory Syndrome (SARS). Eight of 23 passengers who sat “close” to the index case 1 developed SARS. Ten of 88 passengers who sat “far” from the index case also developed SARS. Work through the following example to get a feel for conducting simple epidemiological calculations in R using nothing but two vectors.

using the assignment and concatenation operators to create vectors

Use the assignment operator (<-), and the concatenation function (c()) to create two vectors.

Create a vector called a case that consists of two numbers, the number of exposed people who developed SARS, and the number of unexposed people who developed SARS.

Using the same approach, create a second vector called noncase that consists of the number of exposed people who did not develop disease, and the number of unexposed people who did not develop disease. Again, try to name each element, using the same names you used for the noncase vector.

Category:

Attribution

Charles DiMaggio, PhD. R Practicals. http://www.columbia.edu/~cjd11/charles_dimaggio/DIRE/resources/R/practicalsBookNoAns.pdf

VP Flipbook Maker

Convert your work to digital flipbook with VP Online Flipbook Maker! You can also create a new one with the tool. Try it now!