Quick tour of R basic functionalities

Assignment of a single value to a variable

a is the variable, 3 is the value b is another variable c is a third variable


the result is displayed on the screen the result of the operation is stored in a new variable d the value of d is printed a shortcut for print(d)

Built-in functions


generates a series from 0 to 10 the interval is always 1 but multiplying by a real coefficient can lead to series with any interval


c() concatenates a list of values v is a vector if a vector contains some string, all its elements are considered as strings as well. This is indicated by the double quotes around the "numbers" # Actually, a,b,c, and d are also vectors (which is the simplest object in R), but they contain a single element each. This is the reason why a [1] appears when their value is printed

Manipulating a vector

functions and operations apply directly to each element of a vector, and a vector of the same size is returned.

Reading a vector from a file

subsets of a vector

the fourth element of the vector v elements 2,3, and 4 are returned Elements are returned in the order specified within the concatenation c() The 100 first elements are returned

Data frames (data.frame): an object containing a 2-dimentional array and some associated methods

Read a data frame from a text file. This takes a few seconds (the loading time depends on the network speed).

Printing column names for a data.frame

Prints the column names for a data frame.

Printing row names for a data.frame

Prints the row names for a data frame.

selecting rows from a data.frame

Returns the first row, together with the header. Since there are too many columns, several lines are required. returns the 10 first data rows

Accessing columns in a data frame

This returns the 6152 numbers that are found in the column "mannose" (these are the measures for all the genes at time point 1) returns the names of the columns (column headers) Another way to get the same column, specified by its name rather than index. Yet another way to access the same column The content of single column (in this case the 4th chip) can be assigned to a vector. An element of the vector can then be accessed by adding a single index. This returns the value of the 3201th gene of the 4th chip.

Accessing individual cells

This directly returns the 4th chip for the 3201th gene.

Accessing subsets of a data frame

This returns a rectangular section of the data frame (genes 100 to 120, chips 1 to 3).

Filtering undefined values

For technical reasons, a chip might contain some undefined values. R contains a specific value for undefined values, which are displayed as NA.

The presence of NA values poses problems for some calculation methods. R methods generally include some options allowing to specify the way to treat these values.

One simple way to get rid of NA values is to filter out all the rows which contain one of these.

Selecting rows from a data.frame

This returns columns 5 to 7 for all genes having a higher level than 3 for the 7th chip.

Quit R

The program asks you "Save workspace image? [y/n/c]:" Answer "n" (for the time being, later it can be useful to save the state of the program between two working sessions).