1.8.1

What is the R workspace file on your operating systems?

The R workspace file on my operating systems is .RData.

What is the file path to your R workspace file?

The file path to my R workspace file is “/Users/tiffamee”

What is the name of this workspace file?

The name for this workspace file is “PH 251D”.

1.8.2

By default, which R packages come already loaded?

“.GlobalEnv”

“package:foreign”

“tools:rstudio”

“package:stats”

“package:graphics”

“package:grDevices”

“package:utils”

“package:datasets”

“package:methods”

“Autoloads”

“package:base”

What are the file paths to the default R packages?

[1] “.GlobalEnv”

[2] “/Library/Frameworks/R.framework/Versions/3.3/Resources/library/foreign”

[3] “tools:rstudio”

[4] “/Library/Frameworks/R.framework/Versions/3.3/Resources/library/stats”

[5] “/Library/Frameworks/R.framework/Versions/3.3/Resources/library/graphics”

[6] “/Library/Frameworks/R.framework/Versions/3.3/Resources/library/grDevices”

[7] “/Library/Frameworks/R.framework/Versions/3.3/Resources/library/utils”

[8] “/Library/Frameworks/R.framework/Versions/3.3/Resources/library/datasets”

[9] “/Library/Frameworks/R.framework/Versions/3.3/Resources/library/methods”

[10] “Autoloads”

[11] “/Library/Frameworks/R.framework/Resources/library/base”

1.8.3

List all the object in the current workspace. If there are none, create some data objects.

“aa”
“age_ma_fam”
“al”
“bb”
“bd”
“bdfin”
“dates”
“day”
“e1”
“f”
“maseeting”
“mon”
“mylist”
“n”
“per.act.risk”

“price”

“pts”
“quantity”
“risks”
“subtotal”
“udat”
“x”
“xx”
“y”
“yr”
“yr2”
“z”

Using one expression, remove all the objects in the current workspace.

The expression I used to remove all the objects in the current workspace is “rm(list = ls())”. Typing “ls()” afterwards returns “character(0)”.

1.8.4

One inch equals 2.54 centimeters. Correct the following R code and create a conversion table.

Corrected R code:

inches <- 1:12

centimeters <- inches*2.54

conversion <- cbind(inches, centimeters)

Conversion Table
inches centimeters
1 2.54
2 5.08
3 7.62
4 10.16
5 12.70
6 15.24
7 17.78
8 20.32
9 22.86
10 25.40
11 27.94
12 30.48

1.8.5

At standard temperature and pressure, the freezing and boiling points of water are 0 and 100 degrees Celsius, respectively. What are the freezing and boiling points of water in degrees Fahrenheit?

Using R as a calculator, I got:

Freezing point of water in Fahrenheit: 32

Boiling point of water in Fahrenheit: 212

1.8.6

For the Celsius temperatures 0, 5, 10, 15, 20, 25, …, 80, 85, 90, 95, 100, construct a conversion table that displays the corresponding Fahrenheit temperatures. Hint: to create the sequence of Celsius temperatures use seq(0, 100, 5).

library(knitr)
Celcius <- seq(0, 100, 5)
Fahrenheit <- (9/5)*Celcius + 32
c_to_f <- cbind(Celcius, Fahrenheit)
kable(c_to_f[1:21, ], caption = "Celcius to Fahrenheit")
Celcius to Fahrenheit
Celcius Fahrenheit
0 32
5 41
10 50
15 59
20 68
25 77
30 86
35 95
40 104
45 113
50 122
55 131
60 140
65 149
70 158
75 167
80 176
85 185
90 194
95 203
100 212

1.8.7

Using Table 1.2, explain in words, and use R to illustrate, the difference between modulus and integer divide.

Whereas integer divide (for example, 10%/%3) gives the quotient (3), modulus divide (for example, 10%%3) gives the remainder (1).

1.8.8

From the graph, I can make the generalization that the natural log of e itself (ln(e)) is 1. The natural log of 1 is 0 as always, because anything to the power of 0 is always 1.

1.8.9

From the log of odds, we can see that risk is very “steep” at the extremes - near 0.0 or 1.0. However, in between, risk acts in a buffer zone.

Calculating the accumulated:

library(knitr)

exposure_route <- c("IDU", "RAI", "PNS", "RPVI","IAI", "IPVI", "ROI", "IOI")

risk <- c(67/10000,50/10000,30/10000,10/10000,6.5/10000,5/10000,1/10000,0.5/10000)

probability_infected <- 1-((1-risk)^365)

everything <- cbind(exposure_route, risk, probability_infected)

kable(everything[1:8, ], caption = "Cumulative Risk of Being Infected by HIV")
Cumulative Risk of Being Infected by HIV
exposure_route risk probability_infected
IDU 0.0067 0.914027620481329
RAI 0.005 0.839518685795839
PNS 0.003 0.66601052297303
RPVI 0.001 0.305930112959526
IAI 0.00065 0.211266780124636
IPVI 5e-04 0.166853381929375
ROI 1e-04 0.0358436658079023
IOI 5e-05 0.0180849252236011

These cumulative risks make intuitive sense. Even though they may not have a big difference in risk to begin with, the power portion of calculating probability of getting infected magnifies those differences.

1.8.10

The first time round, the data objects and their values appeared in the environment tab. The second time with “echo = TRUE”, the information on the data objects were returned and appeared in the console space.

1.8.11

When I looked at the log1a file using R, there was nothing inside. When I looked at the log1b file which corresponds to the “echo = TRUE”, there was content: it had the values of the data objects.

1.8.12

The data objects and their values are imported into the environment tab.