R is `GNU S', a freely available language and environment for statistical computing and graphics which provides a wide variety of statistical and graphical techniques: linear and nonlinear modelling, statistical tests, time series analysis, classification, clustering, etc. R is distributed by the Comprehensive R Archive Network (CRAN). R may be downloaded and installed for your hardware from this site.

What you need to do to get started

- Install R for your computer from http://cran.r-project.org/
- Install R Studio for your computer from http://www.rstudio.com/. R studio is an interactive development Environment User Interface for R.
- Refer to R manual, "An introduction to R" http://cran.r-project.org/doc/manuals/r-release/R-intro.html. If you are unfamiliar with R work through Appendix A A Sample Session in this manual http://cran.r-project.org/doc/manuals/r-release/R-intro.html#A-sample-session

USGS R package developed to directly ingest USGS data into R

Examples of functionality I find useful in R.

Perform arithmetic.

> 3*(4+7.3)

[1] 33.9

Assign and work with variables

> g=9.81

> m=30

> f=m*g

> f

[1] 294.3

Combine values into a vector

> a=c(1,2,3,4)

> b=a*2

> b

[1] 2 4 6 8

> ls() # list the objects in your workspace

> rm(f,m,a,b) # Remove objects (to clean up)

> setwd('d:/') # Set working directory - note forward slash

Read a data file. The file boise.txt has
been formatted as follows

1911 10 398

1911 11 395

1911 12 398

1912 1 507

1912 2 421

1912 3 530

...

comprising columns giving the year, month and flow. It is read
as follows

> tt=matrix(scan("boise.txt"),ncol=3,byrow=T)

Read 3276 items

> yr=tt[,1] # put year, month and flow columns in separate
vectors

> mo=tt[,2]

> flow=tt[,3]

> ym=yr+mo/12 # a plotting index in fraction of years

> plot(ym,flow,type="l")

Built in functions

> mean(flow)

[1] 1208.674

> var(flow)

[1] 1800607

Make your own function

sdev=function(x)

{

y=var(x)

return(sqrt(y))

}

Use it

> sdev(flow)

[1] 1341.867

Demonstrate graphics capability

demo(graphics)

Use a package

Packages/Load Package ... select dataRetrieval

Help

??mean

??dataRetrieval