[628] "xkcd.ttf" "pres.7.5a_notes.log" [412] "pres.7.4a.toc" "pres.7.4a.vrb" "pres.7.5a.aux" [415] "pres.7.5a.html" "pres.7.5a.log" "pres.7.5a.nav" [418] "pres.7.5a_notes.aux" "pres.7.5a_notes.out" "pres.7.4a.tex~" [421] "pres.7.5a_notes.pdf" "pres.7.5a_notes.tex" "pres.7.5a_notes.toc" [424] "pres.7.5a.out" "pres.7.5a.pdf" "pres.7.5a.R" [427] "#pres.7.5a.Rmd#" "pres.7.4a_tmp.md" [409] "pres.7.4a.tex" "pres.7.5a.Rmd~" "pres.7.4a_notes.pdf" [391] "pres.7.4a.aux" "pres.7.4a.html" "pres.7.4a.log" [394] "pres.7.4a.nav" "pres.7.4a_notes.aux" "pres.7.4a_notes.log" [397] "pres.7.4a_notes.out" "#pres.7.4a_notes.tex#" "pres.7.4a.snm" [400] "pres.7.4a_notes.tex" "pres.7.4a_notes.tex~" "pres.7.4a_notes.toc" [403] "pres.7.4a.out" "pres.7.4a.pdf" "pres.7.4a.R" [406] "pres.7.4a.Rmd" "pres.7.4a.Rmd~" "pres.7.5a.Rmd" [430] "pres.7.5a.snm" "pres.7.3a.toc" "pres.8.2a.nav" "pres.7.6a_tmp.md" "pres.7.6a.toc" [454] "pres.7.6a.vrb" "pres.8.2a.aux" "pres.8.2a.html" [457] "pres.8.2a.log" "pres.8.2a.md" [460] "pres.8.2a_notes.aux" "pres.7.6a.snm" "pres.8.2a_notes.log" "pres.8.2a_notes.out" [463] "pres.8.2a_notes.pdf" "pres.8.2a_notes.tex" "pres.8.2a_notes.tex~" [466] "pres.8.2a_notes.toc" "pres.8.2a.out" [451] "pres.7.6a.tex" "pres.7.6a.Rmd~" "pres.7.5a.tex" [439] "pres.7.6a_notes.aux" "pres.7.5a_tmp.md" [433] "pres.7.5a.toc" "pres.7.5a.vrb" "pres.7.6a.aux" [436] "pres.7.6a.html" "pres.7.6a.log" "pres.7.6a.nav" "pres.7.6a_notes.log" [448] "pres.7.6a.Rmd" "pres.7.6a_notes.out" [442] "pres.7.6a_notes.pdf" "pres.7.6a_notes.tex" "pres.7.6a_notes.toc" [445] "pres.7.6a.out" "pres.7.6a.pdf" "pres.7.6a.R" "pres.7.3a.vrb" [388] "pres.7.3a_tmp.md" [469] "pres.8.2a.R" "pres.5.2.R" [331] "pres.5.2_notes.log" "pres.5.2_notes.out" "pres.5.2_notes.pdf" [334] "pres.5.2_notes.tex" "pres.5.2_notes.toc" "pres.5.2.out" [337] "pres.5.2.pdf" "#pres.5.2.Rmd#" "pres.5.2.nav" [340] "pres.5.2.Rmd" "pres.5.2.Rmd~" "pres.5.2.snm" [343] "pres.5.2.tex" "pres.5.2.tex~" "pres.5.2_tmp.md" [346] "pres.5.2.toc" "pres.5.2_notes.aux" [328] "pres.5.2.md" "pres.7.2a.aux" "pres.4.pdf" "pres.3.2.R" "pres.3.2.Rmd" [313] "pres.3.2.Rmd~" "pres.4.html" "pres.4.html~" [316] "pres.4_notes.pdf" "pres.4_notes.tex~" [319] "pres.4pdf_knit_.Rmd~" "pres.5.2.log" "pres.4.R" "pres.4.Rmd" [322] "pres.4.Rmd~" "pres.4.tex~" "pres.4_tmp.md~" [325] "pres.5.2.aux" "pres.5.2.html" "pres.5.2.vrb" [349] "pres.7.2a.html" "pres.7.3a.tex" "pres.7.3a_notes.tex" "pres.7.3a.html" "pres.7.3a.log" [373] "pres.7.3a.nav" "pres.7.3a_notes.aux" "pres.7.3a_notes.log" [376] "pres.7.3a_notes.out" "pres.7.3a_notes.pdf" [379] "pres.7.3a_notes.toc" "pres.7.2a.vrb" "pres.7.3a.out" "pres.7.3a.pdf" [382] "pres.7.3a.R" "#pres.7.3a.Rmd#" "pres.7.3a.Rmd" [385] "pres.7.3a.Rmd~" "pres.7.3a.snm" [370] "pres.7.3a.aux" "pres.7.2a.toc" "pres.7.2a.log" [358] "pres.7.2a.out" "pres.7.2a.nav" [352] "pres.7.2a_notes.aux" "pres.7.2a_notes.log" "pres.7.2a_notes.out" [355] "pres.7.2a_notes.pdf" "pres.7.2a_notes.tex" "pres.7.2a_notes.toc" "pres.7.2a.pdf" [367] "pres.7.2a_tmp.md" "pres.7.2a.R" [361] "#pres.7.2a.Rmd#" "pres.7.2a.Rmd" "pres.7.2a.Rmd~" [364] "pres.7.2a.snm" "pres.7.2a.tex" "pres.7.2a.tex~" "pres.8.2a.pdf" "#pres.8.2a.Rmd#" "pres.3.2.html" "pres.9.4a.tex" "pres.9.4a_notes.toc" "pres.9.4a.out" [574] "pres.9.4a.pdf" "pres.9.4a.R" "#pres.9.4a.Rmd#" [577] "pres.9.4a.Rmd" "pres.9.4a.snm" [580] "pres.9.4a_tmp.md" "pres.9.4a_notes.pdf" "pres.9.4a.toc" "pres.9.4a.vrb" [583] "pres.b1.aux" "pres.b1.html" "pres.b1.log" [586] "pres.b1_notes.aux" "pres.b1_notes.log" [571] "pres.9.4a_notes.tex" "pres.9.4a_notes.out" [589] "pres.b1_notes.pdf" [559] "pres.9.3a.tex" "pres.9.3a.out" [553] "pres.9.3a.pdf" "pres.9.3a.R" "#pres.9.3a.Rmd#" [556] "pres.9.3a.Rmd" "pres.9.3a.Rmd~" "pres.9.3a.snm" "pres.9.3a_tmp.md" [568] "pres.9.4a_notes.log" "pres.9.3a.toc" [562] "pres.9.3a.vrb" "pres.9.4a.aux" "pres.9.4a.html" [565] "pres.9.4a.log" "pres.9.4a.nav" "pres.9.4a_notes.aux" "pres.b1_notes.out" "pres.b1_notes.tex" [550] "pres.9.3a_notes.tex" [619] "quiz.toc" "quiz.pdf" [613] "quiz.R" "quiz.Rmd" "quiz.Rmd~" [616] "quiz.snm" "quiz.tex" "quiz_tmp.md" "*shell*" [610] "quiz_notes.toc" "*shell*~" [622] "#*shell*#" "#test.bugs#" "test.bugs" [625] "test.png" "texput.log" "xkcd.png" "quiz.out" "quiz_notes.tex" "pres.b1_notes.toc" "pres.b1_tmp.md" [592] "pres.b1.out" "pres.b1.pdf" "pres.b1.R" [595] "#pres.b1.Rmd#" "pres.b1.Rmd" "pres.b1.Rmd~" [598] "pres.b1.tex" "pres.b1.vrb" "quiz_notes.pdf" [601] "quiz.aux" "quiz.html" "quiz.log" [604] "quiz.nav" "quiz_notes.aux" "quiz_notes.log" [607] "quiz_notes.out" "pres.9.3a_notes.toc" "pres.9.3a_notes.pdf" "pres.8.2a.Rmd" [499] "pres.8.3a.vrb" "#pres.8.3a.Rmd#" [493] "pres.8.3a.Rmd" "pres.8.3a.Rmd~" "pres.8.3a.snm" [496] "pres.8.3a.tex" "pres.8.3a_tmp.md" "pres.8.3a.toc" "pres.9.1a.Rmd~" [490] "pres.8.3a.pdf" "pres.9.1.aux" [502] "pres.9.1.html" "pres.9.1.log" "pres.9.1.md" [505] "pres.9.1.nav" "pres.9.1_notes.aux" "pres.9.1_notes.log" "pres.8.3a.R" "pres.8.3a.out" "pres.9.1_notes.pdf" "pres.8.3a.html" [472] "pres.8.2a.Rmd~" "pres.8.2a.snm" "pres.8.2a.tex" [475] "pres.8.2a_tmp.md" "pres.8.2a.toc" "pres.8.2a.vrb" [478] "pres.8.3a.aux" "pres.8.3a.log" "pres.8.3a_notes.toc" [481] "pres.8.3a.md" "pres.8.3a.nav" "pres.8.3a_notes.aux" [484] "pres.8.3a_notes.log" "pres.8.3a_notes.out" "pres.8.3a_notes.pdf" [487] "pres.8.3a_notes.tex" [508] "pres.9.1_notes.out" "pres.9.1_notes.tex" "pres.9.3a_notes.out" "pres.9.2a_tmp.md" [532] "pres.9.2a.out" "pres.9.2a.pdf" "pres.9.2a.R" [535] "pres.9.2a.Rmd" "pres.9.2a.Rmd~" "pres.9.2a.snm" [538] "pres.9.2a.tex" "pres.9.2a.toc" "pres.9.2a_notes.tex" [541] "pres.9.2a.vrb" "pres.9.3a.aux" "pres.9.3a.html" [544] "pres.9.3a.log" "pres.9.3a.nav" "pres.9.3a_notes.aux" [547] "pres.9.3a_notes.log" "pres.9.2a_notes.toc" [529] "pres.9.2a_notes.pdf" [511] "pres.9.1_notes.toc" "pres.9.1_tmp.md" "pres.9.1.out" "pres.9.1.pdf" [514] "pres.9.1.R" "pres.9.1.Rmd" "pres.9.1.Rmd~" [517] "pres.9.1.snm" "pres.9.1.tex" [520] "pres.9.1.toc" "pres.9.2a_notes.out" "pres.9.1.vrb" "pres.9.2a.aux" [523] "pres.9.2a.html" "pres.9.2a.log" "pres.9.2a.nav" [526] "pres.9.2a_notes.aux" "pres.9.2a_notes.log" [310] "pres.3.2.pdf" "pres.2.4.vrb" "pres.12.2.vrb" "pres.11.2a.md" "pres.10.6a_tmp.md" [100] "pres.10.6a.toc" "pres.10.6a.vrb" "pres.11.2a.aux" [103] "pres.11.2a.html" "pres.11.2a.log" [106] "pres.11.2a.nav" [97] "pres.10.6a.snm" "pres.11.2a_notes.aux" "pres.11.2a_notes.log" [109] "pres.11.2a_notes.out" "pres.11.2a_notes.pdf" "pres.11.2a_notes.tex" [112] "pres.11.2a_notes.toc" "pres.11.2a.out" "pres.11.2a.pdf" [115] "pres.11.2a.R" "pres.10.6a.tex" "pres.10.6a.Rmd~" "pres.11.2a.Rmd" [82] "pres.10.6a.html" [76] "pres.10.5a.snm" "pres.10.5a.tex" "pres.10.5a_tmp.md" [79] "pres.10.5a.toc" "pres.10.5a.vrb" "pres.10.6a.aux" "pres.10.6a.log" "pres.10.6a.Rmd" "pres.10.6a.nav" [85] "pres.10.6a_notes.aux" "pres.10.6a_notes.log" "pres.10.6a_notes.out" [88] "pres.10.6a_notes.pdf" "pres.10.6a_notes.tex" "pres.10.6a_notes.toc" [91] "pres.10.6a.out" "pres.10.6a.pdf" "pres.10.6a.R" [94] "#pres.10.6a.Rmd#" "#pres.11.2a.Rmd#" [118] "pres.11.2a.Rmd~" "pres.10.5a.Rmd" [145] "pres.13.aux" [139] "pres.12.2.Rmd" "pres.12.2.snm" "pres.12.2.tex" [142] "pres.12.2_tmp.md" "pres.12.2.toc" [307] "pres.2.4.toc" "pres.13.html" "pres.12.2.R" "pres.13.log" [148] "pres.13.nav" "pres.13_notes.aux" "pres.13_notes.log" [151] "pres.13_notes.out" "pres.13_notes.pdf" "#pres.12.2.Rmd#" [136] "pres.12.2.pdf" "pres.11.2a.snm" "pres.12.2.log" "pres.11.2a.tex" [121] "pres.11.2a_tmp.md" "pres.11.2a.toc" "pres.11.2a.vrb" [124] "pres.12.2.aux" "pres.12.2.html" [127] "pres.12.2.md" "pres.12.2.out" "pres.12.2.nav" "pres.12.2_notes.aux" [130] "pres.12.2_notes.log" "pres.12.2_notes.out" "pres.12.2_notes.pdf" [133] "pres.12.2_notes.tex" "pres.12.2_notes.toc" "pres.10.5a.Rmd~" [73] "#pres.10.5a.Rmd#" [154] "pres.13_notes.toc" [22] "courses_tmp.md" [16] "courses.pdf" "courses.R" "courses.Rmd" [19] "courses.Rmd~" "courses.snm" "courses.tex" "courses.toc" "courses_notes.toc" "end1.matter" [25] "figure" "getInits.R" "ggmapTemp.png" [28] "head.template" "images" "courses.out" [13] "courses_notes.tex" [31] "macnally.jpg" "beamerHeader.sty" [1] "/home/murray/tmp" #change the current working directory path > setwd ("/home/murray/tmp/") > list.files (path= getwd ()) #list all files (and directories) in the current working directory [1] "A_knit_.rmd~" "A.Rmd~" [4] "cache" "courses_notes.pdf" "courses.aux" "courses.html" [7] "courses.log" "courses.nav" "courses_notes.aux" [10] "courses_notes.log" "courses_notes.out" "junk2.dzslides" "Makefile" "pres.10.5a.R" "pres.10.4.vrb" "pres.10.4.Rmd" "pres.10.4.Rmd~" [55] "pres.10.4.snm" "pres.10.4.tex" "pres.10.4_tmp.md" [58] "pres.10.4.toc" "pres.10.5a.aux" "pres.10.4.pdf" [61] "pres.10.5a.html" "pres.10.5a.log" "pres.10.5a.nav" [64] "pres.10.5a_notes.aux" "pres.10.5a_notes.log" "pres.10.5a_notes.out" [67] "pres.10.5a_notes.pdf" "pres.10.5a_notes.tex" "pres.10.5a_notes.toc" [70] "pres.10.5a.out" "pres.10.5a.pdf" [52] "pres.10.4.R" "pres.10.4.out" "Makefile~" [40] "pres.10.4.aux" [34] "MeansParam.aux" "MeansParam.log" "MeansParam.pdf" [37] "#model.txt#" "model.txt" "NotebookPaper.jpg" "pres.10.4.html" [49] "pres.10.4_notes.toc" "pres.10.4.log" [43] "pres.10.4.nav" "pres.10.4_notes.aux" "pres.10.4_notes.log" [46] "pres.10.4_notes.out" "pres.10.4_notes.pdf" "pres.10.4_notes.tex" "pres.13_notes.tex" "pres.13.out" > getwd () "pres.2.1_notes.tex" "pres.2.1.log" "pres.2.1.nav" [253] "pres.2.1_notes.aux" "pres.2.1_notes.log" "pres.2.1_notes.out" [256] "pres.2.1_notes.pdf" "pres.2.1_notes.toc" "pres.2.1.aux" [259] "pres.2.1.out" "pres.2.1.pdf" "pres.2.1.R" [262] "pres.2.1.Rmd" "pres.2.1.Rmd~" "pres.2.1.snm" [250] "pres.2.1.html" "pres.1.vrb" "pres.2.1_tmp.md" [238] "pres.1old.vrb" [232] "pres.1old.Rmd" "pres.1old.Rmd~" "pres.1old.snm" [235] "pres.1old.tex" "pres.1old_tmp.md" "pres.1old.toc" "pres.1.out" [247] "pres.1.toc" "pres.1.pdf" [241] "pres.1.R" "pres.1.Rmd" "pres.1.Rmd~" [244] "pres.1.snm" "pres.1.tex" "pres.1_tmp.md" [265] "pres.2.1.tex" "pres.2.1.toc" "pres.1old.pdf" [298] "pres.2.4old.vrb" [292] "pres.2.4old.R" "pres.2.4old.Rmd" "pres.2.4old.snm" [295] "pres.2.4old.tex" "pres.2.4old_tmp.md" "pres.2.4old.toc" "pres.2.4.out" [289] "pres.2.4old_notes.toc" "pres.2.4old.out" "pres.2.4.pdf" [301] "pres.2.4.R" "pres.2.4.Rmd" "pres.2.4.Rmd~" [304] "pres.2.4.snm" "pres.2.4.tex" "pres.2.4_tmp.md" "pres.2.4old.pdf" [286] "pres.2.4old_notes.out" "pres.2.4old_notes.pdf" "pres.2.4old_notes.tex" [268] "pres.2.1.vrb" "pres.2.4_notes.log" "pres.2.4.aux" "pres.2.4.html" [271] "pres.2.4.log" "pres.2.4.md" "pres.2.4.nav" [274] "pres.2.4_notes.aux" "pres.2.4_notes.out" "pres.2.4old_notes.aux" "pres.2.4old_notes.log" [277] "pres.2.4_notes.pdf" "pres.2.4_notes.tex" "pres.2.4_notes.toc" [280] "pres.2.4old.aux" "pres.2.4old.html" "pres.2.4old.log" [283] "pres.2.4old.nav" "pres.1old.R" [229] "pres.1old.out" "pres.13.pdf" "pres.14.tex" "pres.14.out" "pres.14.pdf" [178] "pres.14.R" "pres.14.Rmd" "pres.14.Rmd~" [181] "pres.14.snm" "pres.14_tmp.md" "pres.14_notes.tex" [184] "pres.14.toc" "pres.14.vrb" "pres.15.aux" [187] "pres.15.html" "pres.15.log" "pres.15.nav" [175] "pres.14_notes.toc" "pres.14_notes.pdf" "pres.15_notes.log" [163] "pres.13.toc" [157] "pres.13.R" "pres.13.Rmd" "pres.13.Rmd~" [160] "pres.13.snm" "pres.13.tex" "pres.13_tmp.md" "pres.13.vrb" [172] "pres.14_notes.out" "pres.14.aux" [166] "pres.14.html" "pres.14.log" "pres.14.md" [169] "pres.14.nav" "pres.14_notes.aux" "pres.14_notes.log" [190] "pres.15_notes.aux" "pres.15_notes.out" "pres.1old_notes.toc" "pres.1old.html" "pres.1_notes.log" [214] "pres.1_notes.out" "pres.1_notes.pdf" "pres.1_notes.tex" [217] "pres.1_notes.toc" "pres.1old.aux" [220] "pres.1old_knit_.Rmd" [211] "pres.1.nav" "pres.1old.log" "pres.1old.nav" [223] "pres.1old_notes.aux" "pres.1old_notes.log" "pres.1old_notes.out" [226] "pres.1old_notes.pdf" "pres.1old_notes.tex" "pres.1_notes.aux" "pres.1.md" [193] "pres.15_notes.pdf" "pres.15.Rmd" "pres.15_notes.tex" "pres.15_notes.toc" [196] "pres.15.out" "pres.15.pdf" "pres.15.R" [199] "#pres.15.Rmd#" "pres.15.Rmd~" "pres.1.log" [202] "pres.15.snm" "pres.15.tex" "pres.15_tmp.md" [205] "pres.15.toc" "pres.15.vrb" "pres.1.aux" [208] "pres.1.html" #review the current working directory Basic usage y t o r r e c d i i n g o r k w T h e Note that R uses Unix directory slashes ( / ) NOT Windows directory slashes ( \ )
> q () Basic usage n g t t i Q u i NOTE - do not put such a command in a script!
Basic syntax o n s c t i F u n • collections of commands that expand the syntax of R • perform a single action • parameters that alter behaviour
9 10 > seq (from=2,to=10) 8 7 6 5 4 3 2 [1] Basic syntax s i o n n c t F u seq() - a function that generates sequences
[1] 2 ...) function (from = 1, to = 1, by = ((to - from)/(length.out - 1)), length.out = NULL, along.with = NULL, 9 10 8 7 6 5 4 3 > seq (from=2,to=10) Basic syntax s i o n n c t F u seq() - a function that generates sequences • type seq( and then hit the TAB key
8 10 3 6 4 2 [1] > seq (from=2,to=10,by=2) 9 10 8 7 6 5 4 2 [1] > seq (from=2,to=10) Basic syntax s i o n n c t F u seq()
6 10 5 2 [1] > seq (from=2,to=10,length.out=3) 8 10 6 4 2 [1] > seq (from=2,to=10,by=2) 9 10 8 7 6 4 3 2 [1] > seq (from=2,to=10) Basic syntax s i o n n c t F u seq()
6 10 8 2 [1] > seq (from=2,to=10,l=3) 6 10 2 [1] > seq (from=2,to=10,length.out=3) 8 10 6 4 2 [1] > seq (from=2,to=10,by=2) 9 10 7 6 > seq (from=2,to=10) 5 4 3 2 [1] Basic syntax s i o n n c t F u seq() Unique parameter identifiers
Your turn • generate a sequence of 10 numbers that increments by 2 and starting at 8
> seq (from=8, len=10, by=2) [1] 8 10 12 14 16 18 20 22 24 26 Your turn • generate a sequence of 10 numbers that increments by 2 and starting at 8
function (from, to, by, length.out = NULL, along.with = NULL, ...) > apropos ("^seq\\.") > str (seq.Date) ...) function (from = 1, to = 1, by = ((to - from)/(length.out - 1)), length.out = NULL, along.with = NULL, > str (seq.default) "seq.POSIXt" "seq.default" "seq.int" [1] "seq.Date" Basic syntax s i o n n c t F u d e d l o a v e r O seq()
[9] "2000-04-25" > # create a sequence of dates spaced 7 days apart between 29th Feb 2000 and 30th Apr 2000 [7] "2000-04-11" "2000-04-18" [5] "2000-03-28" "2000-04-04" [3] "2000-03-14" "2000-03-21" [1] "2000-02-29" "2000-03-07" > sampleDates to= as.Date ("2000-04-30"), by="7 days") + > sampleDates <- seq (from= as.Date ("2000-02-29"), Basic syntax n s t i o u n c d F a d e r l o O v e seq() > # print (view) these dates
[1] "2000-03-28" > mean ( c (1,2,3,4)) > mean (sampleDates) [1] 2.5 Basic syntax n s t i o u n c d F d e l o a v e r O
> help (mean) Getting help
> ?mean > help (mean) Getting help
> ?mean > help (mean) > example (mean) Getting help
#list all demos available on your system > demo (graphics) > demo () #run the graphics demo Getting help o n s a t i s t r m o n D e
> apropos ('mea') Getting help n g c h i e a r S
> apropos ('mea') > help.search ('mean') #search the local R manuals > help.start () #search the local HTML R manuals Getting help i n g r c h S e a
> apropos ('mea') > help.search ('mean') #search the local R manuals > help.start () #search the local HTML R manuals Getting help i n g r c h S e a
> args (mean) function (x, trim = 0, na.rm = FALSE, ...) #the arguments that apply to the mean function function (x, ...) NULL > args (mean.default) NULL > args (list.files) #the arguments that apply to the list.files function function (path = ".", pattern = NULL, all.files = FALSE, full.names = FALSE, recursive = FALSE, ignore.case = FALSE, include.dirs = FALSE, no.. = FALSE) NULL Getting help s e n t g u m a r i o n n c t F u and dont forget the auto-complete
[10] "package:base" [1] ".GlobalEnv" "Autoloads" "package:methods" [7] "package:datasets" "package:grDevices" "package:utils" [4] "package:graphics" "package:stats" "package:knitr" > search () Package management g e s c k a P a Loaded packages
"package:base" [1] ".GlobalEnv" [10] "Autoloads" "package:methods" "package:datasets" [7] "package:utils" "package:grDevices" "package:graphics" [4] "package:stats" "package:knitr" > library (MASS) "package:MASS" Package management g e s c k a P a Loading packages > search ()
[10] "package:base" > detach ("package:MASS") "Autoloads" "package:methods" [7] "package:datasets" "package:grDevices" "package:utils" [4] "package:graphics" "package:stats" "package:knitr" [1] ".GlobalEnv" > library (MASS) Package management g e s c k a P a Loading packages > search () Unloading packages > search ()
c ("Package", "LibPath", "Version", "Depends", "Built")) > installed.packages () + > installed.packages (fields = Package management s a g e a c k d p l l e s t a i n i n g s t L i
> install.packages () > available.packages () Package management g e s c k a p a l e l a b v a i A g e s c k a p a i n g a l l n s t I
> install.packages ('car') > available.packages () > install.packages () Package management e s k a g p a c l e l a b v a i A g e s c k a p a i n g a l l n s t I - For example, to install the car package
Package management (Rstudio) s a g e a c k e p a b l a i l A v
Package management (Rstudio) s a g e a c k g p l i n t a l I n s
Data types (atomic modes) e s t y p t a d a r y i m a P r Type Description integer whole numbers numeric numbers (floating points) character words logical TRUE/FALSE (0/1)
Data types e s t y p t a d a e d r i v D e Type Description factor categorical variable date (Date) number of days since 1970-01-01 POSIX (Time and Date) number of seconds since 1900-01-01 00:00:00
> Date <- c ('2000-02-29','2002-08-20','2004-02-21') > (Dates<- as.Date (Date)) [1] "2000-02-29" "2002-08-20" "2004-02-21" > mean (Dates) [1] "2002-04-24" Dates • But what about other formats!
> as.Date ('29/02/2000', format='%d/%m/%Y') [1] "2000-02-29" > as.Date ('29th Feb 2000', format='%dth %b %Y') [1] "2000-02-29" Dates check out the help for strptime
[1] "2000-02-29 07:22:30 AEST" > as.POSIXct ('29/02/2000 07:22:30', format='%d/%m/%Y %H:%M:%S') Dates and times
> Dates [1] "2000-02-29" "2002-08-20" "2004-02-21" > format (Dates,format='%d/%m/%Y') [1] "29/02/2000" "20/08/2002" "21/02/2004" > format (Dates,format='%b %Y') [1] "Feb 2000" "Aug 2002" "Feb 2004" > format (Dates,format='%Y') [1] "2000" "2002" "2004" Formatting dates and times
> Date [1] "2000-02-29" "2002-08-20" "2004-02-21" > library (lubridate) [1] "2000-02-29 UTC" "2002-08-20 UTC" "2004-02-21 UTC" > dmy ('29/02/2000') [1] "2000-02-29 UTC" Dates and times packages: lubridate > ymd (Date)
> Dates [1] "2000-02-29" "2002-08-20" "2004-02-21" > library (lubridate) [1] 2000 2002 2004 > class (Date) [1] "character" > decimal_date (Dates) [1] 2000.161 2002.633 2004.139 > week (Dates) [1] 9 34 8 Dates and times packages: lubridate > year (Dates)
> ddays (100) [1] "8640000s (~100 days)" > Dates+100 [1] "2000-06-08" "2002-11-28" "2004-05-31" > Dates+ ddays (100) [1] "2000-06-08" "2002-11-28" "2004-05-31" > Dates+ dweeks (5) [1] "2000-04-04" "2002-09-24" "2004-03-27" Dates and times packages: lubridate
> dmy_hms ('29/02/2000 07:22:30') [1] "2000-02-29 07:22:30 UTC" > dmy_hms ('29/02/2000 07:22:30')+100 [1] "2000-02-29 07:24:10 UTC" > dmy_hms ('29/02/2000 07:22:30')+ ddays (100) [1] "2000-06-08 07:22:30 UTC" > quarter (Dates) [1] 1 3 1 Dates and times packages: lubridate
Storage types Type Description vector 1-d array (same type) matrix 2-d array (same type and length) list collection of vectors data frame 2-d array (any type, same length)
> # a numeric vector > TEMPERATURE <- c (36.1, 30.6, 31, 36.3, 39.9, 6.5, 11.2, 12.8, 9.7, 15.9) > TEMPERATURE [1] 36.1 30.6 31.0 36.3 39.9 6.5 11.2 12.8 9.7 [10] 15.9 Data types o r s e c t V
[1] "Fish" "Rock" "Tree" "Git" > TEMPERATURE > WORDS > WORDS<- c ('Fish', 'Rock', 'Tree', "Git") > # a character vector [10] 15.9 9.7 6.5 11.2 12.8 [1] 36.1 30.6 31.0 36.3 39.9 > TEMPERATURE <- c (36.1, 30.6, 31, 36.3, 39.9, 6.5, 11.2, 12.8, 9.7, 15.9) > # a numeric vector Data types r s t o V e c
TRUE [10] 15.9 TRUE FALSE TRUE [1] > BOOL > BOOL<- c (TRUE, TRUE, FALSE, TRUE) > # a boolean vector [1] "Fish" "Rock" "Tree" "Git" > WORDS > WORDS<- c ('Fish', 'Rock', 'Tree', "Git") > # a character vector 9.7 6.5 11.2 12.8 [1] 36.1 30.6 31.0 36.3 39.9 > TEMPERATURE > TEMPERATURE <- c (36.1, 30.6, 31, 36.3, 39.9, 6.5, 11.2, 12.8, 9.7, 15.9) > # a numeric vector Data types s t o r V e c
[1] 4 4 4 4 4 > rep (4,5) > rep ('Fish',5) [1] "Fish" "Fish" "Fish" "Fish" "Fish" Data types o r s e c t V Regular sequences
"Q10" [1] "Q1" "Q9" [8] "Q8" "Q7" "Q6" "Q5" "Q4" "Q3" "Q2" > QUADRATS > QUADRATS <- c ("Q1","Q2","Q3","Q4","Q5","Q6","Q7","Q8","Q9","Q10") Data types s t o r V e c paste()
"Q10" "Q7" "Q9" [8] "Q8" "Q7" "Q6" "Q5" "Q4" "Q3" "Q2" [1] "Q1" > QUADRATS > QUADRATS <- paste ("Q",1:10,sep="") "Q10" "Q9" [8] "Q8" "Q6" "Q5" "Q4" "Q3" "Q2" [1] "Q1" > QUADRATS > QUADRATS <- c ("Q1","Q2","Q3","Q4","Q5","Q6","Q7","Q8","Q9","Q10") Data types r s c t o V e paste()
[1] 36.1 30.6 31.0 36.3 39.9 > TEMPERATURE 6.5 11.2 12.8 9.7 [10] 15.9 > names (TEMPERATURE) NULL Data types r s t o V e c properties
9.7 15.9 > names (TEMPERATURE) <- QUADRATS 6.5 11.2 12.8 36.1 30.6 31.0 36.3 39.9 Q10 Q9 Q8 Q7 Q6 Q5 Q4 Q3 Q2 Q1 > TEMPERATURE NULL > names (TEMPERATURE) [10] 15.9 9.7 6.5 11.2 12.8 [1] 36.1 30.6 31.0 36.3 39.9 > TEMPERATURE Data types s t o r V e c properties
> SITE <- paste ( rep (LETTERS[1:5], each = 2), 1:2, sep = "") > SITE [1] "A1" "A2" "B1" "B2" "C1" "C2" "D1" "D2" "E1" [10] "E2" Data types r s c t o V e
Your turn Calculate the area of circles with the following radii: • circle A=10cm • circle B=12.3cm • circle C=25.6cm and store the results in a vector with item names reflecting the circle names
> RADIUS <- c (10,12.3,25.6) > names (RADIUS) <- paste ('circle',LETTERS[1:3]) > names (RADIUS) <- paste ('circle',LETTERS[1: length (RADIUS)]) > AREA <- pi*RADIUS^2 > AREA circle A circle B circle C 314.1593 475.2916 2058.8742 Your turn > names (RADIUS) <- c ('circle A', 'circle B', 'circle C') > #OR > #OR even better
[7] "full" "full" "full" "full" > SHADE "full" "no" "no" "no" "no" [1] "no" > SHADE <- rep ( c ("no","full"),each=5) Data types o r s c t V e Factors
Levels: full no "no" [10] full full full full full no no no no [1] no > SHADE > SHADE <- factor (SHADE) [7] "full" "full" "full" "full" "full" "no" "no" "no" [1] "no" > SHADE > SHADE <- rep ( c ("no","full"),each=5) Data types o r s e c t V Factors
Levels: no full > SHADE <- factor (SHADE, levels= c ("no","full")) no no no full full full full [10] full Levels: full no > SHADE [1] no [1] no no no no no full full full full [10] full no > SHADE > SHADE > SHADE <- rep ( c ("no","full"),each=5) [7] "full" "full" "full" "full" "full" "no" "no" "no" "no" [1] "no" > SHADE <- factor (SHADE) Data types s t o r V e c Factors
Levels: no full > SHADE [10] full full full full full no no no no [1] no > SHADE <- gl (2,5,10, c ("no","full")) Data types s t o r V e c Factors
Your turn Create a categorical vector with: - three levels (A, B and C) - four replicates of each level
> gl (3,4,12,lab=LETTERS[1:3]) [1] A A A A B B B B C C C C Levels: A B C Your turn But what if you needed to arrange such that there was only two replicates in a row??
[1] A A B B C C A A B B C C > gl (3,2,12,lab=LETTERS[1:3]) Levels: A B C Your turn
[,1] [,2] > matrix (SHADE,nrow=5) [1,] "no" "full" [2,] "no" "full" [3,] "no" "full" [4,] "no" "full" [5,] "no" "full" Data types s c e t r i M a
[5,] 11.77 13.12 > XY [4,] 15.49 12.20 7.61 16.65 [3,] [2,] 24.03 12.93 8.37 [1,] 16.92 Y > X <- c (16.92,24.03,7.61,15.49,11.77) X Data types s i c e a t r M > Y<- c (8.37,12.93,16.65,12.2,13.12) > XY <- cbind (X,Y)
8.37 12.93 16.65 12.20 13.12 [2,] 24.03 12.93 Y 7.61 15.49 11.77 X 16.92 24.03 [,5] [,4] [,3] [,2] [,1] > rbind (X,Y) [5,] 11.77 13.12 [4,] 15.49 12.20 7.61 16.65 [3,] 8.37 [1,] 16.92 Y X > XY > X <- c (16.92,24.03,7.61,15.49,11.77) Data types s i c e a t r M > Y<- c (8.37,12.93,16.65,12.2,13.12) > XY <- cbind (X,Y)
"E2" Q7 "B2" Q5 "39.9" "C1" Q6 "6.5" "C2" "11.2" Q4 "D1" Q8 "12.8" "D2" Q9 "9.7" "E1" Q10 "15.9" "36.3" "B1" > cbind (TEMPERATURE,SITE) "31" Q3 "A2" "30.6" Q2 "A1" "36.1" Q1 TEMPERATURE SITE Data types s i c e a t r M Beware of mixing data types
2 11.2 Q5 39.9 1 Q6 6.5 2 Q7 2 36.3 Q8 12.8 2 Q9 9.7 2 Q10 15.9 1 Q4 TEMPERATURE SHADE > cbind (TEMPERATURE,SHADE) 31.0 Q3 1 30.6 Q2 1 36.1 Q1 1 Data types s i c e a t r M Beware of mixing data types
9.7 15.9 Levels: no full [3,] 7.61 16.65 [4,] 15.49 12.20 [5,] 11.77 13.12 $SHADE [1] no no no no no full full full full [10] full $TEMPERATURE 8.37 Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 Q9 Q10 36.1 30.6 31.0 36.3 39.9 6.5 11.2 12.8 [2,] 24.03 12.93 [1,] 16.92 $QUADRATS "Q2" COORDINATES = XY, SHADE = SHADE, + TEMPERATURE = TEMPERATURE) > EXPERIMENT $SITE [1] "A1" "A2" "B1" "B2" "C1" "C2" "D1" "D2" "E1" [10] "E2" Y [1] "Q1" "Q3" > EXPERIMENT <- list (SITE=SITE,QUADRATS = QUADRATS, "Q4" "Q5" "Q6" "Q7" [8] "Q8" "Q9" "Q10" $COORDINATES X + Data types s i s t L
Recommend
More recommend