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)) print("Unkown 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
convMeter(2.4,"km")
## [1] "Unkown target unit of length."
You can also embed plots, for example:
x <- rnorm(50)
x
## [1] 1.51879013 -2.19978565 0.22250333 -1.25520011 -1.41438437 0.45922200
## [7] -0.14139011 -0.21575825 -0.13368886 -1.14262711 0.37241070 0.35814037
## [13] -1.81203826 0.86071008 -0.27802874 -0.63784574 -1.26201516 -1.58331248
## [19] -0.29486378 1.88037628 0.96998793 -1.23844797 -1.90986618 2.44102885
## [25] 0.02406827 1.51420227 -0.38628074 -1.06959522 0.18121987 0.82586899
## [31] 0.37345727 -0.22450801 0.19406237 -0.11912223 -0.20672925 0.10236817
## [37] 0.04397668 0.37992084 -0.32094845 -0.26811087 -1.08721280 -1.36191561
## [43] -0.27573258 -0.90788784 0.79248189 -0.46923332 2.15834558 -0.73523491
## [49] -0.28634441 0.58322200
y= mean(x)
y
## [1] -0.1396349
x2<-rnorm(50, mean=50, sd=.1)
x2
## [1] 50.02157 50.07473 50.11035 49.97744 50.07872 50.17245 49.94189 49.98298
## [9] 50.13944 50.04895 49.94739 50.00753 50.11439 50.01161 50.18075 49.80416
## [17] 50.07904 49.92278 49.99624 49.85992 49.96525 49.98379 50.10982 49.89708
## [25] 50.07337 50.12663 50.04090 49.93348 49.96363 50.00132 49.73671 49.93629
## [33] 50.01386 50.14832 49.98620 49.94315 50.19471 49.97154 49.84109 49.97960
## [41] 50.09353 49.84441 49.95888 49.99090 49.97780 49.97051 49.91376 50.07432
## [49] 49.78401 49.98988
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.