head and tails function in R used to get first or last parts of a vector,table, matrix, data frame or function. head() function: Used to get first parts of vector,table, matrix, data frame or function. By default, it will provide first 6 rows. tail() function: Used to get last parts of vector,table, matrix, data frame […]

## Archive for the ‘R Programming’ Category

## How to delete rows from Data Frame in R

There is no direct method to remove rows from R. We can remove the row(s) from Data Frame by creating new Data Frame. How to delete rows from Data Frame in R?

## Difference between sub and gsub in R

sub function replaces the first match of a string, if the parameter is a string vector, replaces the first match of all elements. gsub function replaces all matches of a string. g stands for global. Syntax is same for both sub and gsub. Examples:

## How to Clear the Console in R

We can clear the Console in R using Ctrl+l. We can use cat() function to that. We can also clear console in R using graphical method from RStudio or Rgui. 1. Use Ctrl+L to clear the console. 2. Use cat(“\014”) or cat(“f”) to clear the console.

## Differences between length and nchar in R

length(x) will give how many elements are there in a vector. nchar(x) will give how many letters in each element of x. Examples:

## Installation of r package dplyr

dplyr is R package for data manipulation using the Split Apply Combine Methodology, the next iteration of the very popular plyr package. As per R documentation dplyr is “A Grammar of Data Manipulation”. It’s the next iteration of plyr, focused on tools for working with data frames > install.packages(“dplyr”) Installing package into ‘C:/Users/pinnapav/Documents/R/win-library/3.3’

## How to get first and last rows of Data Frame in R

We can get first n rows of Data Frame using head() function and can get last n rows of Data Frame using tail() function. Syntax of head() and tail() functions: head(data.frame,number_of_first_rows) tail(data.frame,number_of_last_rows)

## How to get list of User defined Variables in R

Variables are containers to for storing data in any programming language. We get the list of variables defined in R Programming Language using ls(), objects() functions. R Variables starting with dot(.) are hidden, they can be listed using ls(all:names=TRUE). Examples:

## R Installation on Windows

1. Goto cran(Comprehensive R Archive Network) website. R Software Link