Julia — Sep 21, 2013, 8:45 PM
#Julia Wei
#Homework Chapter 1
#PH 251D
#09.21.2013
#1.1. The R workspace on my computer is .RData. The computer file path to the workspace file is obtained using the getwd function.
getwd()
[1] "C:/Users/Julia/Documents"
#1.2. By default, the R packages that come already loaded is found through search ().
search()
[1] ".GlobalEnv" "package:knitr" "package:stats"
[4] "package:graphics" "package:grDevices" "package:utils"
[7] "package:datasets" "package:methods" "Autoloads"
[10] "package:base"
#The File paths to the default R packages are found through the searchpaths function.
searchpaths()
[1] ".GlobalEnv"
[2] "C:/Users/Julia/Documents/R/win-library/3.0/knitr"
[3] "C:/Program Files/R/R-3.0.1/library/stats"
[4] "C:/Program Files/R/R-3.0.1/library/graphics"
[5] "C:/Program Files/R/R-3.0.1/library/grDevices"
[6] "C:/Program Files/R/R-3.0.1/library/utils"
[7] "C:/Program Files/R/R-3.0.1/library/datasets"
[8] "C:/Program Files/R/R-3.0.1/library/methods"
[9] "Autoloads"
[10] "C:/PROGRA~1/R/R-30~1.1/library/base"
#1.3. The objects in the current workspace are obtained through ls().
ls()
character(0)
x <- c(1,2,3,4,5)
gender <- c("boy", "boy", "girl")
ls()
[1] "gender" "x"
rm(list = ls())
ls()
character(0)
#1.4.
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.
celsius <- c(0,100)
fahrenheit <- ((9/5)*celsius) +32
fahrenheit
[1] 32 212
#1.6.
celsius <- seq(0, 100, 5)
fahrenheit <- ((9/5)*celsius) + 32
cbind(celsius, fahrenheit)
celsius fahrenheit
[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.
JWkg <- 120/2.2
JWm <- 5/3.3
BMI <- JWkg/(JWm^2)
BMI
[1] 23.76
#1.8.Integer divide is when you do division and discard the remainder. Modulus is the remainder you get when you divide one number by another.
10%/%3
[1] 3
10%%3
[1] 1
#1.9.
curve(log(x), 0, 6)
abline(v = c(1, exp(1)), h = c(0,1), lty = 2)
#1.10.
curve(x/(1-x), 0, 1)
curve(log(x/(1-x)), 0, 1)
#1.11.
n <- 365
risk.per.ten.thousand.exposures <- c(67, 50, 30, 10, 6.5, 5, 1, 0.5)
risk.per.act <- c((risk.per.ten.thousand.exposures)/10000)
risk <- 1-(1-risk.per.act)^n
acts <- c("IDU", "RAI", "PNS", "RPVI", "IAI", "IPVI", "ROI", "IOI")
names(risk) <- acts
risk
IDU RAI PNS RPVI IAI IPVI ROI IOI
0.91403 0.83952 0.66601 0.30593 0.21127 0.16685 0.03584 0.01808
#1.12.?
source("/Users/Julia/Documents/HW1job01.R")
source("/Users/Julia/Documents/HW1job01.R", echo = TRUE)
> n <- 365
> risk.per.ten.thousand.exposures <- c(67, 50, 30, 10,
+ 6.5, 5, 1, 0.5)
> risk.per.act <- c((risk.per.ten.thousand.exposures)/10000)
> risk <- 1 - (1 - risk.per.act)^n
> acts <- c("IDU", "RAI", "PNS", "RPVI", "IAI", "IPVI",
+ "ROI", "IOI")
> names(risk) <- acts
> risk
IDU RAI PNS RPVI IAI IPVI ROI IOI
0.91403 0.83952 0.66601 0.30593 0.21127 0.16685 0.03584 0.01808
#1.13.?
sink("/Users/Julia/Documents/HW1job01.log1a")
source("/Users/Julia/Documents/HW1job01.R")
sink()
sink("/Users/Julia/Documents/HW1job01.log1b")
source("/Users/Julia/Documents/HW1job01.R", echo = TRUE)
> n <- 365
> risk.per.ten.thousand.exposures <- c(67, 50, 30, 10,
+ 6.5, 5, 1, 0.5)
> risk.per.act <- c((risk.per.ten.thousand.exposures)/10000)
> risk <- 1 - (1 - risk.per.act)^n
> acts <- c("IDU", "RAI", "PNS", "RPVI", "IAI", "IPVI",
+ "ROI", "IOI")
> names(risk) <- acts
> risk
IDU RAI PNS RPVI IAI IPVI ROI IOI
0.91403 0.83952 0.66601 0.30593 0.21127 0.16685 0.03584 0.01808
sink()
#HW1job01.log1a is empty while HW1job01.log1b has a copy of what is in HW1job01.R
#1.14.
source("/Users/Julia/Documents/HW1job02.R")
[1] 0.01808 0.03584 0.16685 0.21127 0.30593 0.66601 0.83952 0.91403
#what is shown is the what is within the show() function in the other file.