Imperial College/Courses/Fall2009/Synthetic Biology (MRes class)/'R' Tutorial/Crash Course

From OpenWetWare
Jump to navigationJump to search
Fall 2009 - Synthetic Biology (MRes class)

Home        Lecture        'R' Tutorial        Resources        Literature

<html> <body> <!-- Start of StatCounter Code --> <script type="text/javascript"> var sc_project=3315864; var sc_invisible=0; var sc_partition=36; var sc_security="8bb2efcd"; </script>

<script type="text/javascript" src="http://www.statcounter.com/counter/counter_xhtml.js"></script><noscript><div class="statcounter"><a class="statcounter" href="http://www.statcounter.com/"><img class="statcounter" src="http://c37.statcounter.com/3315864/0/8bb2efcd/0/" alt="blog stats" /></a></div></noscript> <!-- End of StatCounter Code -->

</body> </html>

Introduction to 'R'




Slides

Useful online resources

Crash Course in R

Running 'R'

  • > Starting R
    • Find and Select 'R' within your Programs list
  • > Running 'R' from command line
    • Once started, 'R' will open an interactive console.
    • You can then type 'R' commands. Remember, 'R' commands are case sensitive.
    • Commands are separated either by a semi-colon (‘;’), or by a newline.
    • The vertical arrow keys on the keyboard can be used to scroll forward and backward through a command history.
  • > Running 'R' From a script (strongly suggested)
    • 'R' can runs commands that have been saved in a text file (you can use your prefered text editor)
    • Commands are separated either by a semi-colon (‘;’), or by a newline.
    • For good practice, comments should be added to the script by using '#', like '# this is my comment'
    • to execute the script, type in the 'R' console source("path_to_my_script/my_script.R")

Exit R

  • type q() in 'R' console

Getting help

  • Check online tutorials (see above)
  • Type help(command_name) or ?command_name like help(length), ?length

Objects in R

  • > Data Types available
    • integer
    • numeric
    • character
    • complex
    • logical
  • > Data Structures available
    • Vectors
      • A vector is an ordered collection of elements and is equivalent to a single row or a single column in a spreadsheet. Most vectors are numerical (1,2,3…), but logical vectors (TRUE, FALSE, TRUE…) and vectors of character strings (“apples”, “oranges”, “pears”…) also are possible.
    • Matrices and Arrays
      • A matrix is a set of vectors extending over two dimensions; an array is a set of vectors extending over two or more dimensions. A matrix, therefore, is a two-dimensional array.
    • Factors
      • A factor is a vector object used to specify a discrete classification (grouping) of the components of other vectors of the same length. R provides both ordered and unordered factors.
    • Lists
      • A list is a vector containing different types of elements, such as (1, TRUE, “apples”…)
    • Data Frames
      • A data frame is a matrix-like object consisting of two or more lists or vectors (or matricies or data frames), each of which contains the same number of elements. The objects in a data frame need not be of the same type.
  • > Listing objects in memory
    • type objects() in 'R' console.
  • > Clearing memory
    • type rm(object_name)
    • to clear all memory type rm(objects())

Import / Export Data

Graphics in 'R'

Useful functions

    • Generating regular expressions
      • seq()
      • rep()
      • 1:30
    • ....
  • Write your own functions