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:

convMeter <- 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)) stop("Unknown target unit of length.") 
  else return(val*mult)}

convMeter(23, "foot")
## [1] 75.45932
Inches = convMeter(40,"inch")
sprintf("40 meters are equivalent to %f inches", Inches)
## [1] "40 meters are equivalent to 1574.804000 inches"
convMeter(40)
## [1] 1574.804
convMeter(5, "cm")
## [1] 500
x <- rnorm(50)
x
##  [1] -1.41073449 -0.39222347  3.30754813  0.38451298  1.14441557  0.27385802
##  [7]  0.09441600  0.88010498  2.49433219 -2.66544613  2.01588987  1.52762822
## [13] -0.76109837 -0.98675091 -1.50011471  1.67848562 -0.66619133 -1.38405166
## [19]  1.57489342 -0.82575881 -1.61445657 -0.44809126  0.64533021 -1.80758726
## [25]  1.05742951  0.24515923  0.76787553 -0.98016728  0.48772261  0.64279347
## [31]  0.61605478  1.54027328  0.56489661  0.06573237  0.48298138  0.25839836
## [37] -1.00097506  0.50977096 -2.02113616  0.03423762 -1.39482911  0.39874237
## [43] -0.06624886  0.59223825  0.99860121  1.53325226  0.23708828  0.93916020
## [49] -0.71931901  1.23282280
y = mean(x)
y
## [1] 0.1716293
x2 <- rnorm(50, mean = 50, sd=.1)
x2
##  [1] 49.95775 50.06399 50.12266 49.85156 49.92694 50.08103 49.95993 49.88495
##  [9] 50.15134 50.02191 50.15750 50.03298 50.08609 50.20216 50.00036 49.93328
## [17] 49.99180 50.15564 49.89034 49.96977 49.94523 49.97725 49.83018 49.98749
## [25] 49.95550 49.94564 50.01768 50.05858 50.05283 50.06569 49.98156 50.15741
## [33] 50.07489 50.13726 49.92469 50.03118 50.00539 49.94788 49.89499 49.86428
## [41] 49.98443 49.90654 50.05192 49.94185 50.07546 49.92201 49.92444 50.15855
## [49] 50.10205 50.10026
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
data("Titanic")
View(Titanic)

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.