Showing posts with label R programming. Show all posts
Showing posts with label R programming. Show all posts

Sunday, January 25, 2015

How to Create and Publish R package on CRAN : Step-by-Step Guide

Requirements:
  • R Studio (This tutorial is based on R studio 0.98.501)
  • Beginner level R programming skills
  • devtools package (to build and compile the code)
  • roxygen2 package (to create the documentation)
Lets break it down into 7 simple steps as following:
  1. Create R project
  2. Create function(s)
  3. Create  description file
  4. Create help file(s)
  5. Build, load and check the package
  6. Export package
  7. Submit on CRAN
Step 1

1.1  Open R Studio. Create a new project using "file > new project > new directory > empty project". Give directory name.


Saturday, August 16, 2014

Simple R tricks for data processing

Count unique values from a column in matrix or data-frame
# Find number of unique first names
length(levels(data$fname))

Count specific values in vector or column
# Find number of occurrences for "ac" in vector nlist
table(nlist)["value"]


Tuesday, May 13, 2014

Create network with igraph in 4 simple steps

Lets say, we have a data-frame with node-node-edge values as following,


Now we will build a network based on this data.

Step 1: Load the data and do basic validity checks.

Thursday, February 13, 2014

R Markdown using R Studios


R has markdown functionality (similar to IPython) packages which helps us to create web reports and dynamic web content. Lets go through a quick tutorial about creating a R Markdown.

Make sure you have latest version of R Studio and following two packages installed:

  • knitr 
  • markdown

Open R studio, click File > New File > R Markdown

Tuesday, January 28, 2014

R session History and Image management

There are many powerful IDEs for R but if you are a command line user managing command history of your sessions or reusing objects you are working with, may not be that easy. Here are two simple commands which can help us with the same.

>  savehistory(file_name)


Friday, October 25, 2013

R programming: Matrix Management


In this post lets see few basic functions to deal with matrix creation and manipulation.

# Lets assume we wish to convert existing vector v into matrix m
v <- 1:12

# Lets create matrix m from elements of v with 3 row and 4 columns
m <- matrix(v, 3, 4)

# Declare matrix with all 0 values
m <- matrix(0, 3, 4)

Wednesday, October 2, 2013

R programming: Vector management

Create vector with values 1 to 10
Use: v <- seq(1, 10)
Use: v <- 1:10

Create vector of numbers from 10 to 20 and 30 to 40
Use: v <- c(10:20, 30:40)

Create vector of size 10 initialized to zero.
Use: v <- rep(0,10)

Create vector of 5, 10, 15 ... 100
Use:  v <- seq(5, 50, 5)

Saturday, September 28, 2013

R programming: Four power-commands to explore data

This is a simple tutorial demonstrating 4 useful commands to explore data. 

Requirement:
  1. You have R installed
  2. You have this data file 
Go to R command line interface by just entering R in terminal. It should look something like following,

Saturday, September 21, 2013

Basics of R programming: File management

R is growing rapidly and most preferred language of data analysts according to kdnuggets. It is not only replacing highend softwares like SAS but also MS Excel. Recently I saw one video of Google analytics with R, which is pretty cool. Generally we will deal with txt, csv, tsv or rda extentions of data files. Following simple function can be used to read a CSV file,
 dat <- read.table("Sales.csv",header=TRUE,sep=',')