R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

sqrt(2)
## [1] 1.414214
#conversion Function
convMeters <- function (val, to="inch"){
  mult <- switch (to, inch=39.3701, foot=3.28084, yard=1.09361, mile=0.000621371, cm=100, NA)
  if(is.na(mult)) print("Unknown target unit of length.") else return(val*mult)}
convMeters(23, "foot")
## [1] 75.45932
Inches = convMeters(40, "inch")
sprintf("40 meters are equivalent to %f inches", Inches)
## [1] "40 meters are equivalent to 1574.804000 inches"
convMeters(40)
## [1] 1574.804
convMeters(5, "cm")
## [1] 500
convMeters(2.4, "km")
## [1] "Unknown target unit of length."
#Random function generates a vector of random normal variables with first argument n the sample size. Each time we call this function, we rnorm() will get a different answer. if we want the same number we set the seed using set.seed()

set.seed(30)
x<- rnorm(50)
x
##  [1] -1.28851820 -0.34768941 -0.52162885  1.27347316  1.82452060 -1.51130794
##  [7]  0.11050805 -0.76079623 -0.66989702  0.27451969 -1.02327202 -1.81939791
## [13] -0.66778981 -0.05929799  0.88016591  0.26851292 -0.01957938 -0.52494697
## [19] -1.40933143 -1.83398921 -0.15831429  0.75442657 -0.91212962  0.79993114
## [25]  1.49055300 -1.09640199 -0.53422069 -1.42120303 -1.24273830  0.23193618
## [31] -1.72520250  0.61486070  0.72687514 -0.04219020  0.21600180  1.76973639
## [37]  0.22035091  0.53147867  2.16970096 -2.93441824 -0.99556463  1.16955322
## [43] -0.48003984 -1.66886763  1.13399719 -0.31759583  0.17585799 -0.62550955
## [49] -1.63952782 -0.67148442
y = mean(x)
y
## [1] -0.2457178
x2<-rnorm(50, mean=50, sd= .1)
x2
##  [1] 49.91510 50.01232 49.93803 49.82863 50.07158 49.90845 50.25984 49.94884
##  [9] 49.91336 50.03872 50.09741 50.03992 50.03483 49.97095 50.15766 50.08463
## [17] 49.90806 50.04006 50.03544 50.16578 50.11148 49.92594 50.20109 49.99744
## [25] 49.99148 50.05016 49.92748 50.11054 49.93674 49.98028 50.08515 49.94338
## [33] 49.98478 49.95711 50.22187 49.79664 49.89340 50.15721 49.92696 50.04505
## [41] 50.05644 49.97782 49.95307 50.05727 49.87068 50.02613 50.01002 50.02696
## [49] 50.02119 49.86163

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.