Reshape R package, reshape2, melt and cast

In this tutorial we will look at Reshape R package, reshape2, melt and cast functions. Reshape R package – Introduction and concepts In this tutorial on data frame we saw the reshape function that can be used to convert multiple columns of a dataframe to multiple rows. In the current tutorial we look at the … Read more

Pretty printing in R using the Format function.

In the previous tutorial we looked at printing R objects using the print and cat functions. In this tutorial we look at Pretty printing in R using the Format function.. If R encounters a custom object then it calls the toString() generic method of that object. The sprintF method is a wrapper over C’s sprintf … Read more

How to write Functions in R

In this tutorial we look at how to write functions in R. What are functions? Functions are user defined pieces of code that perform a desired operation on given input(s) and return the output back to the user. The main characteristics of functions are: They contain lines of code enclosed within a body. The variable … Read more

Control Structures in R

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 … Read more

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 … Read more

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 … Read more

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: > array(1:8,dim=c(2,2,2)) , , 1 … Read more