Difference between revisions of "R tutorial"
From Organic Design wiki
m (→Useful commands in the R environment) |
m |
||
| Line 21: | Line 21: | ||
*Quickest way to learn R: use the Contributed Documentation (''http://cran.stat.auckland.ac.nz/other-docs.html'') | *Quickest way to learn R: use the Contributed Documentation (''http://cran.stat.auckland.ac.nz/other-docs.html'') | ||
*Thousands of pages of documentation including short guides / reference cards | *Thousands of pages of documentation including short guides / reference cards | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
====Obtaining help in R==== | ====Obtaining help in R==== | ||
| Line 42: | Line 30: | ||
demo() <font color="red"># Demonstrations of R Functionality</font> | demo() <font color="red"># Demonstrations of R Functionality</font> | ||
demo(graphics) <font color="red"># Demonstration or graphics Functionality</font> | demo(graphics) <font color="red"># Demonstration or graphics Functionality</font> | ||
| − | |||
---- | ---- | ||
====Useful commands in the R environment==== | ====Useful commands in the R environment==== | ||
| Line 54: | Line 41: | ||
q() <font color="red"># Terminate an R Session → prompted to Save workspace image? [y/n/c]:</font> | q() <font color="red"># Terminate an R Session → prompted to Save workspace image? [y/n/c]:</font> | ||
---- | ---- | ||
| + | ====Command prompt==== | ||
| + | * <font color="red>''Type commands after the prompt (<font color="blue">></font>) e.g. ''</font> | ||
| + | <font color="blue">></font> x <- 1:10 <font color="red"># assignment of 1 to 10 to an object called 'x'</font> | ||
| + | <font color="blue">></font> x <font color="red"># Returning the x object to the screen</font> | ||
| + | [1] 1 2 3 4 5 6 7 8 9 10 | ||
| + | * <font color="red>''Continuation of commands is expected after the plus symbol (<font color="blue">+</font>) e.g.'' </font> | ||
| + | > x <- 1: <font color="red"># partial command → parser is expecting more information</font> | ||
| + | <font color="blue">+ </font> 10 | ||
| + | > x | ||
| + | [1] 1 2 3 4 5 6 7 8 9 10 | ||
| + | ---- | ||
| + | ====Assignment of objects==== | ||
| + | * objects must start with a letter ''[A-Za-z]'' | ||
| + | * "<-" The arrow assigns information to the object on the left | ||
| + | x <- 3.14 # Assignment to the left | ||
| + | x | ||
| + | x = 3.14 # Using equals is always left assignment (not recommended) | ||
| + | x | ||
| + | 3.14 -> x # Assignment to the right | ||
;# Create a vector | ;# Create a vector | ||
;# Create a matrix | ;# Create a matrix | ||
Revision as of 23:51, 14 March 2006
TODO
- Tasks available from web which utilze example data available in R - object assignment, subsetting, plotting, mathematical functions, sorting etc (20 tasks?)
- Usage/interaction within environment
- Bioconductor resources/vignettes(including downloading)
- Bioconductor basics (any resources for limma out there?)
- Twenty tasks to do in R
- Use a contributed guide as a template fo a list of twenty tasks to do. It must cover;
- Memory based, can write to → .RData file
- File handling
- Object creation
- Different types of data
- Quiting R
- Recommended contributed guide/reference card
Contributed material
- usingR-2.pdf Chapter 1 → Starting up.
- MGEDI → installing R/Bioconductor p30 - p34 (documentation/help)
Resources
- Quickest way to learn R: use the Contributed Documentation (http://cran.stat.auckland.ac.nz/other-docs.html)
- Thousands of pages of documentation including short guides / reference cards
Obtaining help in R
help.start() # Browser based help documentation help() # Help on a topic ? ls # alternative help method on ls function apropos(mean) # Find Objects by (Partial) Name example(mean) # Run an Examples Section from the Online Help demo() # Demonstrations of R Functionality demo(graphics) # Demonstration or graphics Functionality
Useful commands in the R environment
search() # Give Search Path for R Objects searchpaths() # Give Full Search Path for R Objects ls() # List objects objects() # alternate function to list objects data() # Publically available datasets rm(list=ls()) # Remove Objects from a Specified Environment save.image() # Save R Objects q() # Terminate an R Session → prompted to Save workspace image? [y/n/c]:
Command prompt
- Type commands after the prompt (>) e.g.
> x <- 1:10 # assignment of 1 to 10 to an object called 'x' > x # Returning the x object to the screen [1] 1 2 3 4 5 6 7 8 9 10
- Continuation of commands is expected after the plus symbol (+) e.g.
> x <- 1: # partial command → parser is expecting more information + 10 > x [1] 1 2 3 4 5 6 7 8 9 10
Assignment of objects
- objects must start with a letter [A-Za-z]
- "<-" The arrow assigns information to the object on the left
x <- 3.14 # Assignment to the left x x = 3.14 # Using equals is always left assignment (not recommended) x 3.14 -> x # Assignment to the right
- Create a vector
- Create a matrix
- Create a list
- Subsetting/Indexing
- Indexing from a vector
- Indexing from a matrix
- Indexing from a list
- Plotting data
- Labelling/colours etc
- Ab lines?
- how to read help
- Apropos/example/demo/find etc
- Help example
- ls/rm
- quit



