Data Analysis In: Dr. Lai Jiangshan Lai@ibcas - Ac.cn
Data Analysis In: Dr. Lai Jiangshan Lai@ibcas - Ac.cn
Data analysis in
Dr. Lai Jiangshan
[email protected]
Field of research
Forest ecology
R workshop in China
1. Introduction to R
3. Graphics in R
What is R?
• The R statistical programming language is a free open
source package based on the S language developed by Bell
Labs.
• The language is very powerful for writing programs.
• Many statistical functions are already built in.
• Contributed packages expand the functionality to cutting
edge research.
• Since it is a programming language, generating computer
code to complete tasks is required.
Creators of R
Ross Ihaka
University of Auckland, new Zealand
Since 1997, there was a core team, who was able to modify
the source code of R.
Robert Gentleman
The creators of the R
• Go to www.r-project.org
• Downloads: CRAN
• Select base.
• Install Rstudio
20
Basics
• Highly Functional
– Everything done through functions
– Strict named arguments
– Abbreviations in arguments OK (e.g. T for
TRUE)
• Object Oriented
– Everything is an object
– “<-” or “=” is an assignment operator
– “X <- 5”: X GETS the value 5
Getting Help in R
• From Documentation:
– ?t.test
– help(t.test)
– example(t.test)
– help.start()
• Documents: “Introduction to R”
Help website
• A typical user wiki.
• http://www.statmethods.net/
• Also called Quick-R. Gives very productive
• direct help. Also for users coming from other
• programming languages.
• http://mathesaurus.sourceforge.net/
• Dictionary for programming languages (e.g. R for
• Matlab users).
• Just using Google (type e.g. \R rnorm" in the
• search eld) can also be very productive.
Data Structures
• Supports virtually any type of data
• Numbers, characters, logicals (TRUE/ FALSE)
• Simplest: Vectors and Matrices
• Data Frame: Rectangular Data Set
• Lists: Can Contain mixed type variables
Packages install.views("Environmetrics")
39
https://cran.r-project.org/web/packages/
Practice in Adding Packages
#Adding Packages
#install packages
rda
install.packages("vegan")
library(vegan)
rda
Input and output in R
read.table Read a text file into a data frame