R Tutorial

Interview
Question & Answers
Tutorials

R Introduction

Next- R Character String

R Programming tutorialR is a programming language, used for statistical analysis, data analytics and scientific research. It is one of the most popular languages used by statisticians, data analysts, researchers and marketers to retrieve, clean, analyze, visualize and present data.

R is simple and effective programming language, allows branching and looping as well as modular programming using functions. R allows integration with the procedures written in the C, C++, .Net, Python or FORTRAN languages for efficiency.

The post "Best R programming tutorial for data science" covers following topics.

1. Features of R

2. R Installation

3. Basic commands

4. R- Data Types

5. R - Strings

6. R - Matrices

7. R - Vectors

 

Features of R

  • Open Source Software
  • Object Oriented Design
  • It runs on all popular platforms – Windows, Linux and Mac.
  • R can be linked with common programming platforms like C++ and Java, which makes it possible to embed R within applications.
  • Provides effective data handling and storage facility.
  • It provides large, coherent and integrated collection of tools for data analysis. It can be executed within commercial analytics tools like SAS.
  • R code can be easily written and packaged. It is easy to create and distribute them as package.

R Installation

1. Download and install the latest version of R from https://cran.r-project.org/bin/windows/base/
2. After R is installed, install R studio, which is very good and widely recognized R tool.

Open Rstudio to execute commands.

Basic commands

You can write commands in workspace (top left window). Click on Run button on top. It shows output in Console (placed in bottom left).
Basic commands Output

Basic Commands Output
sqrt(25) [1] 25
2^2+5 [1] 9

# Assign value to variable

x<- "Good Morning"

x

[1] “Good Morning”

 

Command Name ls()
Description : ls() lists all variables and functions defined in the workspace. It returns names of variables declared. Suppose we have declared two variables
Try these commands in R Visual Studio
aa <- 8
x <- “Good Morning”
>ls() command will return
[1] "aa" "x"
> ls.str()
Returns
aa : num 8
x : chr "Good Morning"
# Deleting Variables
rm(x,aa) # the rm function removes permanently

 

R – Data Types

Description : Data types are used to store different types of values in variables. Based on variables’ data type, operating system allocates memory.

R has following wide variety of data types.

1. scalars(like character, wide character, integer, floating point, double floating point, Boolean etc),
2. vectors (numerical, character, logical),
3. matrices,
4. data frames
5. lists.

R - Strings

Any value written in single quote and double quotes is treated as string. Double quotes or single quote can not be inserted into a string starting and ending with single quote.

For more details on R string click here

 

R - Vector - Most Simplest structure in R

If data has only one dimension, like a set of digits, vectors can be used to represent it. There are six types of atomic vectors - logical, integer, double, complex, character and raw. The modes and storage modes for the different vector types are listed in the following table.

For more details on R Vector click here

 

R – Matrices

  • Used when data is a higher dimensional array
  • Contains only data of a single class. For example only character or numeric.
For More Details on R Matrices Click here

 

</table

Next- R Character String