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:
convMeters <- function(val, to="inch"){
mult<- switch(to,inch=39.3701,foot=3.28034,yard=1.09361,mile=0.000621371,cm=100,NA)
if(is.na(mult)) stop("Unknown target unit of length.") else return(val*mult)
}
convMeters(40)
## [1] 1574.804
convMeters(5,"cm")
## [1] 500
yard = convMeters(456,"yard")
inch = convMeters(4,"inch")
yard
## [1] 498.6862
inch
## [1] 157.4804
You can also embed plots, for example:
x<-rnorm(50)
x
## [1] 0.17577364 1.51656782 -2.06704015 -0.20517783 -0.15463402 -0.10188042
## [7] 0.39654259 0.98997028 -0.52659039 -0.46677797 -2.37770743 0.26505501
## [13] 1.38499429 -0.94871809 -1.65661196 0.24752146 -0.78641988 0.32532084
## [19] -0.86368968 -2.19742180 1.11176078 -1.06126928 -0.12292623 -0.68771888
## [25] 0.62382630 1.12903415 -0.51706606 -0.61316458 -1.46478685 -1.00194969
## [31] 1.40835814 1.24544382 0.96270036 1.27217662 -0.85934963 -1.73595983
## [37] -0.56242437 -1.75876757 -0.69155090 0.38306596 0.89957685 0.08608157
## [43] -2.64596632 -1.00926458 -1.37454161 0.84638308 -0.98541617 0.01891949
## [49] -0.99428008 -0.89545806
y=mean(x)
y
## [1] -0.3209091
x2<-rnorm(50,mean=50,sd=1)
x2
## [1] 50.32045 48.16075 48.82154 49.78792 48.67194 49.55742 48.96531 50.15899
## [9] 49.71761 52.23276 48.94110 48.68595 50.85847 51.96364 48.30676 51.03223
## [17] 48.67216 49.40018 48.88664 49.68042 50.52455 50.99851 50.52832 51.41027
## [25] 51.80771 51.00773 51.23338 49.92610 48.94814 51.92015 49.10326 49.02245
## [33] 48.63630 47.82155 50.33465 49.38012 49.90568 50.61195 50.55812 49.79117
## [41] 50.40032 50.64631 50.65339 50.39739 50.27255 51.18326 50.60311 51.18298
## [49] 49.04955 49.01357
set.seed(1303)
rnorm(50)
## [1] -1.1439763145 1.3421293656 2.1853904757 0.5363925179 0.0631929665
## [6] 0.5022344825 -0.0004167247 0.5658198405 -0.5725226890 -1.1102250073
## [11] -0.0486871234 -0.6956562176 0.8289174803 0.2066528551 -0.2356745091
## [16] -0.5563104914 -0.3647543571 0.8623550343 -0.6307715354 0.3136021252
## [21] -0.9314953177 0.8238676185 0.5233707021 0.7069214120 0.4202043256
## [26] -0.2690521547 -1.5103172999 -0.6902124766 -0.1434719524 -1.0135274099
## [31] 1.5732737361 0.0127465055 0.8726470499 0.4220661905 -0.0188157917
## [36] 2.6157489689 -0.6931401748 -0.2663217810 -0.7206364412 1.3677342065
## [41] 0.2640073322 0.6321868074 -1.3306509858 0.0268888182 1.0406363208
## [46] 1.3120237985 -0.0300020767 -0.2500257125 0.0234144857 1.6598706557
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.