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] 2.12996240 -0.38267414 -0.14551482 0.31990360 0.17376220 -0.64709997
## [7] -0.23725191 0.99293218 -1.28942042 -0.89249216 1.62752365 -0.47505807
## [13] -0.33420364 0.18123299 0.59225766 -0.14031250 -0.33784880 0.24231461
## [19] 0.05304490 -1.70745092 0.28403698 1.70813143 0.06568275 -0.39768550
## [25] 1.69215471 0.36092535 1.18270895 -1.09256508 0.31151938 -0.57333899
## [31] 1.04510574 -0.53884554 1.35738698 -0.79225943 1.14772933 -0.71190333
## [37] 0.59964816 0.84203907 -0.72126146 -0.22372354 -0.69220659 0.57668062
## [43] -0.46460019 1.25950383 -0.38092632 -0.39664894 -0.37488591 1.47748588
## [49] 1.72809697 0.66756326
y=mean(x)
y
## [1] 0.1733831
x2<-rnorm(50,mean=50,sd=1)
x2
## [1] 50.06292 50.65461 50.74018 49.77460 51.17287 50.25191 49.33100 49.76004
## [9] 48.98579 49.60973 48.73900 48.92469 51.66010 49.51481 50.04353 50.84750
## [17] 49.39909 50.20104 49.39664 49.89829 49.31501 49.34712 51.16383 49.71246
## [25] 50.19894 51.21248 48.90798 50.76707 51.13940 50.16305 51.08885 49.89741
## [33] 50.62306 50.92079 49.48367 49.62680 48.69110 51.58192 50.32529 48.30870
## [41] 50.08858 50.10043 50.42208 50.96656 49.12739 50.15491 48.26641 50.17707
## [49] 50.36247 49.80624
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.