This tutorial looks at some of the common control structures in R. Control Structures define the flow of the program and decides which path the program takes. This decision is based on the evaluation of a variable. These are the basic types of control structures: Introduction if a variable satisfies a particular condition follow path […]

# Category: R

## Data Structures in R, Data Frame Operations

In the previous tutorial we saw an introduction to factors and data frames in R. In this tutorial we look at some more functions that can be used on data frames. Multiple columns into single column – stack() The first function that we look at today is the stack function. It can be used to […]

## Data Structures in R – factors and Data Frame

In the earlier tutorials we learnt vectors, list, arrays and matrix. In this tutorial we will look at factors and data frame Factors Factors in R store categorical data. Categorical data has discreet values. For example, a vector of months of births of students in a class contains discreet values or categorical data. Their class […]

## Data Structures – Matrix and Array in R

In the previous tutorial we saw atomic vectors and list. In this tutorial we look at Matrix and Array in R. Array An array is a vector with additional attributes dim which stores the dimension of the array and dimnames which stores the names of the dimensions. Here’s an example:

1 2 3 4 5 6 7 8 9 10 11 12 | > array(1:8,dim=c(2,2,2)) , , 1 [,1] [,2] [1,] 1 3 [2,] 2 4 , , 2 [,1] [,2] [1,] 5 7 [2,] 6 8 |

This creates a 2,2,2 […]

## Basic Data Structures in R

The basic data structures in R can be divided in to two types Types of data structures Homogeneous All the elements in the data structure are of same type (string, number, boolean etc) Heterogeneous The elements in the data structure can be of mixed type. Basic Data structures in R Here are the basic data […]

## Source R File

In this tutorial we look at how to Source R File from the console. R commands can be run from a file using the source command. create a test file called test.R

1 | vi test.R |

add the following line in the file

1 | cat("Sourcing from R file\n") |

Now open R and fire this command (give the absolute or relative path to […]

## List all Objects in R

All entities in R are called objects. They can be arrays, numbers, strings, functions. In this tutorial we look at how to list all objects in R. Get a list of all objects function name : objects() or ls() the objects() or ls() function can be used to get a vector of character strings of […]

## Assignment Operators in R

Two important assignment operators in R are <- and = . Lets look at some examples. This first example assignes 3 to variable x. Notice that a space before and after the assignment operator makes the code more readable.

1 2 3 4 | > x <- 3 > x [1] 3 > |

It is also possible to chain assignments

1 2 3 4 5 | > a<-b<-3 > a [1] 3 > b [1] 3 |

In this next example we declare a […]

## How to Start R, Stop R and save workspace

How to Start R?

## 15 Page Tutorial for R

For Beginners in R, here is a 15 page example based tutorial that covers the basics of R. Starting R – Trivial tutorial on how to start R for those just wondering what to do next after downloading R. Assignment Operator – Two important assignment operators in R are <- and = Listing Objects – […]