getting started with r and r commander -...

31
Getting started with R and R Commander

Upload: haquynh

Post on 11-May-2018

228 views

Category:

Documents


6 download

TRANSCRIPT

Page 1: Getting started with R and R Commander - UC3Mhalweb.uc3m.es/esp/Personal/personas/jmmarin/esp/... · I Useful packages:agricolae, Rcmdr, Rcmdr.TeachingDemos, lattice, Deducer. References

Getting started with R and R Commander

Page 2: Getting started with R and R Commander - UC3Mhalweb.uc3m.es/esp/Personal/personas/jmmarin/esp/... · I Useful packages:agricolae, Rcmdr, Rcmdr.TeachingDemos, lattice, Deducer. References

Getting started with R and R Commander

Contents

I Starting R

I Changing language to English in RI Loading R Commander (and other packages)

I Loading data in R CommanderI From a fileI From R librariesI Creating data in R/ R CommanderI Creating data in R Commander

I Installing R

I Installing packages in R

Page 3: Getting started with R and R Commander - UC3Mhalweb.uc3m.es/esp/Personal/personas/jmmarin/esp/... · I Useful packages:agricolae, Rcmdr, Rcmdr.TeachingDemos, lattice, Deducer. References

Starting RI Go to the Start menu (bottom left corner)I Then to Programs, look for RI Click on the thick blue R 2...I R uses the language from the windows version of your

computer.I It is possible to change language (apart from English) to

German, French, Italian... Right click the shortcut icon in thedesktop. Type, e.g., Language=it after the texts in Targetfield. Apply and restart R.

Page 4: Getting started with R and R Commander - UC3Mhalweb.uc3m.es/esp/Personal/personas/jmmarin/esp/... · I Useful packages:agricolae, Rcmdr, Rcmdr.TeachingDemos, lattice, Deducer. References

Changing language to English in RI Go to Edit menu, then GUI preferences...

Page 5: Getting started with R and R Commander - UC3Mhalweb.uc3m.es/esp/Personal/personas/jmmarin/esp/... · I Useful packages:agricolae, Rcmdr, Rcmdr.TeachingDemos, lattice, Deducer. References

Changing language to English in RI Type english in the top right field and hit OK

Page 6: Getting started with R and R Commander - UC3Mhalweb.uc3m.es/esp/Personal/personas/jmmarin/esp/... · I Useful packages:agricolae, Rcmdr, Rcmdr.TeachingDemos, lattice, Deducer. References

Loading R Commander - first methodI From the top menu, choose Packages and Load package...

Page 7: Getting started with R and R Commander - UC3Mhalweb.uc3m.es/esp/Personal/personas/jmmarin/esp/... · I Useful packages:agricolae, Rcmdr, Rcmdr.TeachingDemos, lattice, Deducer. References

Loading R Commander - first method cont.I From the drop-down menu, choose Rcmdr

Page 8: Getting started with R and R Commander - UC3Mhalweb.uc3m.es/esp/Personal/personas/jmmarin/esp/... · I Useful packages:agricolae, Rcmdr, Rcmdr.TeachingDemos, lattice, Deducer. References

Loading R Commander - second method

I Type in the R Console window library(Rcmdr) and hit OK

Page 9: Getting started with R and R Commander - UC3Mhalweb.uc3m.es/esp/Personal/personas/jmmarin/esp/... · I Useful packages:agricolae, Rcmdr, Rcmdr.TeachingDemos, lattice, Deducer. References

Main window of R Commander

Page 10: Getting started with R and R Commander - UC3Mhalweb.uc3m.es/esp/Personal/personas/jmmarin/esp/... · I Useful packages:agricolae, Rcmdr, Rcmdr.TeachingDemos, lattice, Deducer. References

Main window of R Commander

Page 11: Getting started with R and R Commander - UC3Mhalweb.uc3m.es/esp/Personal/personas/jmmarin/esp/... · I Useful packages:agricolae, Rcmdr, Rcmdr.TeachingDemos, lattice, Deducer. References

R CommanderI If you accidently close the Rcmdr window, type Commander()

in the R Console and hit OK

Page 12: Getting started with R and R Commander - UC3Mhalweb.uc3m.es/esp/Personal/personas/jmmarin/esp/... · I Useful packages:agricolae, Rcmdr, Rcmdr.TeachingDemos, lattice, Deducer. References

Loading data in R Commander - from a fileI We want to load Nations.txt located in ...I C:/Program Files/R/R-2.13.1/library/Rcmdr/etc/ ...I And call it mydata

Page 13: Getting started with R and R Commander - UC3Mhalweb.uc3m.es/esp/Personal/personas/jmmarin/esp/... · I Useful packages:agricolae, Rcmdr, Rcmdr.TeachingDemos, lattice, Deducer. References

Loading data in R Commander - from a file cont.

Page 14: Getting started with R and R Commander - UC3Mhalweb.uc3m.es/esp/Personal/personas/jmmarin/esp/... · I Useful packages:agricolae, Rcmdr, Rcmdr.TeachingDemos, lattice, Deducer. References

Loading data in R Commander - from a file cont.I Starting from C:, follow the path till you get to the file

Page 15: Getting started with R and R Commander - UC3Mhalweb.uc3m.es/esp/Personal/personas/jmmarin/esp/... · I Useful packages:agricolae, Rcmdr, Rcmdr.TeachingDemos, lattice, Deducer. References

Loading data in R Commander - from a file cont.I mydata automatically becomes your active Data set and you

can view its contents by clicking on the View data set

Page 16: Getting started with R and R Commander - UC3Mhalweb.uc3m.es/esp/Personal/personas/jmmarin/esp/... · I Useful packages:agricolae, Rcmdr, Rcmdr.TeachingDemos, lattice, Deducer. References

Loading data in R Commander - from R librariesI You can load data from any package of R:

Page 17: Getting started with R and R Commander - UC3Mhalweb.uc3m.es/esp/Personal/personas/jmmarin/esp/... · I Useful packages:agricolae, Rcmdr, Rcmdr.TeachingDemos, lattice, Deducer. References

Loading data in R Commander - from R libraries cont.I Remember to double-click!

Page 18: Getting started with R and R Commander - UC3Mhalweb.uc3m.es/esp/Personal/personas/jmmarin/esp/... · I Useful packages:agricolae, Rcmdr, Rcmdr.TeachingDemos, lattice, Deducer. References

Loading data in R Commander - from R libraries cont.

I In Active data set, you can Select/Refresh, etc and Getvariable names

I In Manage variables in active data set, Recode, etc

Page 19: Getting started with R and R Commander - UC3Mhalweb.uc3m.es/esp/Personal/personas/jmmarin/esp/... · I Useful packages:agricolae, Rcmdr, Rcmdr.TeachingDemos, lattice, Deducer. References

Creating data in R/ R Commander

I We want to create three vectors X: 11,12,13,16,16,17,18,21,Y: 14,15,15,15,16,16,16,17, Z: 11,11,11,12,19,20,20,20

I And then merge them together as one data set, one vector percolumn

I Type in the Script Window, highlight everything, press Submit

x = c(11,12,13,16,16,17,18,21)

y = c(14,15,15,15,16,16,16,17)

z = c(11,11,11,12,19,20,20,20)

data.xyz = data.frame(x,y,z)

data.xyz

Page 20: Getting started with R and R Commander - UC3Mhalweb.uc3m.es/esp/Personal/personas/jmmarin/esp/... · I Useful packages:agricolae, Rcmdr, Rcmdr.TeachingDemos, lattice, Deducer. References
Page 21: Getting started with R and R Commander - UC3Mhalweb.uc3m.es/esp/Personal/personas/jmmarin/esp/... · I Useful packages:agricolae, Rcmdr, Rcmdr.TeachingDemos, lattice, Deducer. References

Creating data in R Commander (not recommended)I Often crashes the programme

Page 22: Getting started with R and R Commander - UC3Mhalweb.uc3m.es/esp/Personal/personas/jmmarin/esp/... · I Useful packages:agricolae, Rcmdr, Rcmdr.TeachingDemos, lattice, Deducer. References

Creating data: Alternatives

Type in the Script Window, highlight everything, press Submit:

I Data <- edit(as.data.frame(NULL))

I Alternatively: x = scan()

Introduce values. When finishing, press Intro twice.

Page 23: Getting started with R and R Commander - UC3Mhalweb.uc3m.es/esp/Personal/personas/jmmarin/esp/... · I Useful packages:agricolae, Rcmdr, Rcmdr.TeachingDemos, lattice, Deducer. References

Installing RI Go to CRAN website http://cran.r-project.org/

Page 24: Getting started with R and R Commander - UC3Mhalweb.uc3m.es/esp/Personal/personas/jmmarin/esp/... · I Useful packages:agricolae, Rcmdr, Rcmdr.TeachingDemos, lattice, Deducer. References

Installing RI Choose the platform, eg, Windows

Page 25: Getting started with R and R Commander - UC3Mhalweb.uc3m.es/esp/Personal/personas/jmmarin/esp/... · I Useful packages:agricolae, Rcmdr, Rcmdr.TeachingDemos, lattice, Deducer. References

Installing RI Choose the base

Page 26: Getting started with R and R Commander - UC3Mhalweb.uc3m.es/esp/Personal/personas/jmmarin/esp/... · I Useful packages:agricolae, Rcmdr, Rcmdr.TeachingDemos, lattice, Deducer. References

Installing RI Click on Download... and ...I save the .exe file on your machine/external hard-driveI You can get to the .exe file faster by simply typing

http://cran.es.r-project.org/bin/windows/base/R-2.13.1-win32.exe in your browser

Page 27: Getting started with R and R Commander - UC3Mhalweb.uc3m.es/esp/Personal/personas/jmmarin/esp/... · I Useful packages:agricolae, Rcmdr, Rcmdr.TeachingDemos, lattice, Deducer. References

Installing R

I Double click on the saved file and ...I Follow the installation steps

I You can install R on an external hard-drive (you need around150MB of space), thus not necessarily on your laptop/desktop

I Set the language to Spanish/English

Page 28: Getting started with R and R Commander - UC3Mhalweb.uc3m.es/esp/Personal/personas/jmmarin/esp/... · I Useful packages:agricolae, Rcmdr, Rcmdr.TeachingDemos, lattice, Deducer. References

Installing packages in RI From the top menu, choose Packages and Install package(s)...

Page 29: Getting started with R and R Commander - UC3Mhalweb.uc3m.es/esp/Personal/personas/jmmarin/esp/... · I Useful packages:agricolae, Rcmdr, Rcmdr.TeachingDemos, lattice, Deducer. References

Installing packages in RI Select CRAN mirror (place from which you will download

packages), eg, from Lyon in France

Page 30: Getting started with R and R Commander - UC3Mhalweb.uc3m.es/esp/Personal/personas/jmmarin/esp/... · I Useful packages:agricolae, Rcmdr, Rcmdr.TeachingDemos, lattice, Deducer. References

Installing packages in RI From the drop-down list, select the packages (press CTRL and

hold it, whilst clicking with the mouse button on severalpackages)

I Useful packages: agricolae, Rcmdr, Rcmdr.TeachingDemos,lattice, Deducer

Page 31: Getting started with R and R Commander - UC3Mhalweb.uc3m.es/esp/Personal/personas/jmmarin/esp/... · I Useful packages:agricolae, Rcmdr, Rcmdr.TeachingDemos, lattice, Deducer. References

References and additional reading material aboutRCommander

I ”The R Commander: A Basic-Statistics Graphical UserInterface to R”. John Fox Journal of Statistical Software2005, Volume 14, Issue 9.

I cran.r-project.org/doc/contrib/Karp-Rcommander-intro.pdf