1.1 The R workspace file is “Environment.” The workspace directory is: C:/Users/ktran_000/Documents/R/applied-epi-hw and the name of the workspace files is HW1.
1.2 Default packages and their file paths include:
.GlobalEnv
tools:rstudio
package:stats, C:/Program Files/R/R-3.1.1/library/stats
package:graphics, C:/Program Files/R/R-3.1.1/library/graphics
package:grDevices, C:/Program Files/R/R-3.1.1/library/grDevices
package:utils, C:/Program Files/R/R-3.1.1/library/utils
package:datasets, C:/Program Files/R/R-3.1.1/library/datasets
package:methods, C:/Program Files/R/R-3.1.1/library/methods
Autoloads
package:base, C:/PROGRA~1/R/R-3.1.1/library/base
1.3 Created objects
colors
mydf
object
x
x <- c(1:20)
colors <- c("red", "blue", "green", "yellow")
object <- c("square", "cirle", "triangel", "trapezoid")
mydf <- data.frame(colors, object)
The code rm(list = ls()); ls() was used to remove all the objects in the workspace.
1.4 Corrected code:
inches <- 1:12
centimeters <- inches*2.54
cbind(inches, centimeters)
## inches centimeters
## [1,] 1 2.54
## [2,] 2 5.08
## [3,] 3 7.62
## [4,] 4 10.16
## [5,] 5 12.70
## [6,] 6 15.24
## [7,] 7 17.78
## [8,] 8 20.32
## [9,] 9 22.86
## [10,] 10 25.40
## [11,] 11 27.94
## [12,] 12 30.48
1.5 Converting Celsius to Fahrenheit degrees
R code
C1 <-0
F1 <- c(((9/5)*C1)+32)
C2 <- 100
F2 <- c(((9/5)*C2)+32)
Freezing point: 0 deg C = 32 deg F
Boiling point: 100 deg C = 212 deg F
1.6 Celsius-Fahrenheit conversion table
R code
C <- c(seq(0, 100, 5))
F <- c(((9/5)*C)+32)
cbind(C, F)
## C F
## [1,] 0 32
## [2,] 5 41
## [3,] 10 50
## [4,] 15 59
## [5,] 20 68
## [6,] 25 77
## [7,] 30 86
## [8,] 35 95
## [9,] 40 104
## [10,] 45 113
## [11,] 50 122
## [12,] 55 131
## [13,] 60 140
## [14,] 65 149
## [15,] 70 158
## [16,] 75 167
## [17,] 80 176
## [18,] 85 185
## [19,] 90 194
## [20,] 95 203
## [21,] 100 212
1.7 BMI calculation
R code
r kg <- weight/2.2 m <- height/3.3 bmi <- kg/(m*m)
1.8 Integer divide (%/%) produces the integer quotient without the remainder and the modulus (%%) produces the remainder for the integer divide.
1.9 The natural log (ln) illustrates how fast it takes for the base e to grow.
1.10 The log odds stretch out proportions that are close to 0 and 1 and compress proportions close to 0.5.
1.11 The cumulative risks do not make sense intuitively unless coverted to percentages or per 10,000.
1.12 When “source” was run, all the lines of code in the ASCII file was run and the output values appeared in the “Environment” tab.
When “echo=TRUE” was added and run, the code lines in the ASCII file was added to the Console.
1.13 Nothing is saved into the log when the source file is ran without “echo=TRUE” statement. With that statement, the source R code is copy into the log.
1.14 Source-ing the given command produces shows 8 risk calculations.