SlideShare uma empresa Scribd logo
1 de 10
Baixar para ler offline
R Language
INTRODUCTION:

R is an open source programming language and software environment for statistical computing

and graphics. The R language is widely used among statisticians and data miners for developing

statistical software and data analysis. But, we are going to integrate R with Hadoop in order to

manage BigData efficiently. Here, we have tried to figure out some basic commands of R

followed by logical implementation using R as well.


BASIC COMMANDS:


GetDirectory:

getwd()             [ R language is case sensitive ]


Assignment:

Single value:


s < - 3 or s = 3     [The value of s is 3]


Multiple values:


s < - c (1, 2, 3)    [The value of s is 1, 2, 3]


Or


s < - c (1:3)        [The value of s is 1, 2, 3]
Mean:

mean(x)              [The mean of x i.e. 1, 2, 3 is 2]


Variance:

var(x)               [The variance of x i.e.1, 2, 3 is 1]


Linear Model:

lm_1 < - lm(y~x)     [The linear model between two variables will be shown]


Graphical Representation:

plot (lm_1)           [The linear model will be graphically represented]


Summary:

summary (lm_1)        [The summary of the linear model will be shown]


List of variables:

ls ()                 [ The list of all variables used will be shown]


Reading .csv files:

read.table ( file=”sample.csv”)


                      [Files can be read in this way, mostly csv files]
Reading .xls files:

install.packages("gdata")             [ It can be done manually too. Go to Packages at the


                                      top. Select any location, preferably USA (CA 1).


                                      Then select gdata from the list. ]




library(gdata)                        [ Use of Library for reading an Excel file. ]




setwd("D:/R Statistics")              [ Set working directory ]




y=read.xls("iris.xls")                 [Read the .xls/.xlsx file that is present in the working


                                       directory. ]




y                                      [ Print the contents of the excel file. ]




These were some basic knowledge on R. Now, some logical implementations are being laid

down below:
LOGICAL IMPLEMENTATION:


Conditional:

Example:
x=5            # Creates sample data


if(x!=5)
{
    print(1)
} else
{
    print(2)
}




*else should be printed after “}”, not in a new line.


Output:


[1] 2


Ifelse:

Ifelse statements operate on vectors of variable length.


Syntax:


ifelse(test, true_value, false_value)
Example:


x = 1:10        # Creates sample data

ifelse(x<5 | x>8, x, 0)

Output:


[1]        1 2 3 4 0 0 0 0 9 10




For loop:

Example:


x=5
for(i in seq(along=x))
{
    if(x==5)
           print(1)
    else
           print(2)
}


Output:
[1] 1




*The use of “along” prints the value for once only. At the same time, the absence of along
will print the value x times likewise;
x=5
for(i in seq(x))
{
    if(x==5)
           print(1)
    else
           print(2)
}

Output:
[1]    1
[1]    1
[1]    1
[1]    1
[1]    1




While Loop:


Example:

z=0
while(z < 5)

{
     z=z+2
     print(z)
}
Output:

[1] 2
[1] 4
[1] 6
Apply loop:

Example 1(Coloumwise operation):

x= matrix(c(1:9),3,3)

apply(x, 1, sum)

Output:

[1] 12 15 18

Example 2(Rowwise operation):

x= matrix(c(1:9),3,3)

apply(x, 2, sum)

Output:

[1] 6 15 24



lapply:

Applies a function to elements in a list or a vector and returns the results in a list.
Exmple:

# create a list with 2 elements
l = list(a = 1:10, b = 11:20)
# the mean of the values in each element
lapply(l, mean)

Output:

$a
[1] 5.5

$b
[1] 15.5
# the sum of the values in each element
lapply(l, sum)

Output:

$a
[1] 55

$b
[1] 155

sapply:
Exmple1:

li = list("klaus","martin","georg")
sapply(li,toupper)



Output:


[1] "KLAUS" "MARTIN" "GEORG"

Exmple2:

# create a list with 2 elements
l <- list(a = 1:10, b = 11:20)
# mean of values using sapply
l.mean <- sapply(l, mean)
# what type of object was returned?
class(l.mean)
[1] "numeric"
# it's a numeric vector, so we can get element "a" like this
l.mean[['a']]

Output:

[1] 5.5
vapply:
vapply is similar to sapply, but has a pre-specified type of return value, so it can be safer (and
sometimes faster) to use.

Exmple:

l <- list(a = 1:10, b = 11:20)
# fivenum of values using vapply
l.fivenum <- vapply(l, fivenum, c(Min.=0, "1st Qu."=0, Median=0, "3rd Qu."=0, Max.=0))
class(l.fivenum)
[1] "matrix"
# let's see it
l.fivenum


Output:

          a            b
Min.     1.0          11.0
1st Qu. 3.0           13.0
Median 5.5            15.5
3rd Qu. 8.0           18.0
Max.    10.0           20.0




REFERENCE:

[1] http://www.r-project.org

[2] http://www.cyclismo.org/tutorial/R/types.html

[3] http://manuals.bioinformatics.ucr.edu/home/programming-in-r

[4] http://nsaunders.wordpress.com/2010/08/20/a-brief-introduction-to-apply-in-r
Basic and logical implementation of r language

Mais conteúdo relacionado

Mais procurados

Data analysis with R
Data analysis with RData analysis with R
Data analysis with RShareThis
 
Functional programming with_scala
Functional programming with_scalaFunctional programming with_scala
Functional programming with_scalaRaymond Tay
 
Why Haskell Matters
Why Haskell MattersWhy Haskell Matters
Why Haskell Mattersromanandreg
 
Functional Programming by Examples using Haskell
Functional Programming by Examples using HaskellFunctional Programming by Examples using Haskell
Functional Programming by Examples using Haskellgoncharenko
 
How To Use Higher Order Functions in Scala
How To Use Higher Order Functions in ScalaHow To Use Higher Order Functions in Scala
How To Use Higher Order Functions in ScalaBoldRadius Solutions
 
Why async and functional programming in PHP7 suck and how to get overr it?
Why async and functional programming in PHP7 suck and how to get overr it?Why async and functional programming in PHP7 suck and how to get overr it?
Why async and functional programming in PHP7 suck and how to get overr it?Lucas Witold Adamus
 
High-Performance Haskell
High-Performance HaskellHigh-Performance Haskell
High-Performance HaskellJohan Tibell
 
Functional Programming, simplified
Functional Programming, simplifiedFunctional Programming, simplified
Functional Programming, simplifiedNaveenkumar Muguda
 
The Ring programming language version 1.5.3 book - Part 22 of 184
The Ring programming language version 1.5.3 book - Part 22 of 184The Ring programming language version 1.5.3 book - Part 22 of 184
The Ring programming language version 1.5.3 book - Part 22 of 184Mahmoud Samir Fayed
 
Collections In Scala
Collections In ScalaCollections In Scala
Collections In ScalaKnoldus Inc.
 
Python list 28_10_2020
Python list 28_10_2020Python list 28_10_2020
Python list 28_10_2020Sugnan M
 

Mais procurados (19)

Data analysis with R
Data analysis with RData analysis with R
Data analysis with R
 
Functional programming with_scala
Functional programming with_scalaFunctional programming with_scala
Functional programming with_scala
 
Why Haskell Matters
Why Haskell MattersWhy Haskell Matters
Why Haskell Matters
 
Language R
Language RLanguage R
Language R
 
R language
R languageR language
R language
 
Sql
SqlSql
Sql
 
Functional Programming by Examples using Haskell
Functional Programming by Examples using HaskellFunctional Programming by Examples using Haskell
Functional Programming by Examples using Haskell
 
Ggplot2 v3
Ggplot2 v3Ggplot2 v3
Ggplot2 v3
 
How To Use Higher Order Functions in Scala
How To Use Higher Order Functions in ScalaHow To Use Higher Order Functions in Scala
How To Use Higher Order Functions in Scala
 
sets and maps
 sets and maps sets and maps
sets and maps
 
Why async and functional programming in PHP7 suck and how to get overr it?
Why async and functional programming in PHP7 suck and how to get overr it?Why async and functional programming in PHP7 suck and how to get overr it?
Why async and functional programming in PHP7 suck and how to get overr it?
 
High-Performance Haskell
High-Performance HaskellHigh-Performance Haskell
High-Performance Haskell
 
Practical cats
Practical catsPractical cats
Practical cats
 
Functional Programming, simplified
Functional Programming, simplifiedFunctional Programming, simplified
Functional Programming, simplified
 
Array in c++
Array in c++Array in c++
Array in c++
 
R Language Introduction
R Language IntroductionR Language Introduction
R Language Introduction
 
The Ring programming language version 1.5.3 book - Part 22 of 184
The Ring programming language version 1.5.3 book - Part 22 of 184The Ring programming language version 1.5.3 book - Part 22 of 184
The Ring programming language version 1.5.3 book - Part 22 of 184
 
Collections In Scala
Collections In ScalaCollections In Scala
Collections In Scala
 
Python list 28_10_2020
Python list 28_10_2020Python list 28_10_2020
Python list 28_10_2020
 

Destaque (20)

Strategy pattern
Strategy patternStrategy pattern
Strategy pattern
 
ประวัติส่วนตัว
ประวัติส่วนตัวประวัติส่วนตัว
ประวัติส่วนตัว
 
Observer pattern
Observer patternObserver pattern
Observer pattern
 
Solvents used pharmaceutically(j.c)
Solvents used pharmaceutically(j.c)Solvents used pharmaceutically(j.c)
Solvents used pharmaceutically(j.c)
 
Paper review
Paper review Paper review
Paper review
 
Database management system chapter15
Database management system chapter15Database management system chapter15
Database management system chapter15
 
Apache hadoop & map reduce
Apache hadoop & map reduceApache hadoop & map reduce
Apache hadoop & map reduce
 
Map reduce
Map reduceMap reduce
Map reduce
 
R with excel
R with excelR with excel
R with excel
 
Matrix multiplication graph
Matrix multiplication graphMatrix multiplication graph
Matrix multiplication graph
 
Database management system chapter16
Database management system chapter16Database management system chapter16
Database management system chapter16
 
Cloud testing
Cloud testingCloud testing
Cloud testing
 
Mediator pattern
Mediator patternMediator pattern
Mediator pattern
 
Clustering manual
Clustering manualClustering manual
Clustering manual
 
Observer pattern
Observer patternObserver pattern
Observer pattern
 
Parallel searching
Parallel searchingParallel searching
Parallel searching
 
Parallel computing chapter 2
Parallel computing chapter 2Parallel computing chapter 2
Parallel computing chapter 2
 
Parallel computing chapter 3
Parallel computing chapter 3Parallel computing chapter 3
Parallel computing chapter 3
 
Parallel computing(2)
Parallel computing(2)Parallel computing(2)
Parallel computing(2)
 
Report writing(short)
Report writing(short)Report writing(short)
Report writing(short)
 

Semelhante a Basic and logical implementation of r language

Presentation R basic teaching module
Presentation R basic teaching modulePresentation R basic teaching module
Presentation R basic teaching moduleSander Timmer
 
Morel, a Functional Query Language
Morel, a Functional Query LanguageMorel, a Functional Query Language
Morel, a Functional Query LanguageJulian Hyde
 
LISP: Introduction To Lisp
LISP: Introduction To LispLISP: Introduction To Lisp
LISP: Introduction To LispLISP Content
 
Morel, a data-parallel programming language
Morel, a data-parallel programming languageMorel, a data-parallel programming language
Morel, a data-parallel programming languageJulian Hyde
 
Ejercicios de estilo en la programación
Ejercicios de estilo en la programaciónEjercicios de estilo en la programación
Ejercicios de estilo en la programaciónSoftware Guru
 
Scala. Introduction to FP. Monads
Scala. Introduction to FP. MonadsScala. Introduction to FP. Monads
Scala. Introduction to FP. MonadsKirill Kozlov
 
Introduction to R
Introduction to RIntroduction to R
Introduction to Ragnonchik
 
Fp in scala part 2
Fp in scala part 2Fp in scala part 2
Fp in scala part 2Hang Zhao
 
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docxINFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docxcarliotwaycave
 
Loops and functions in r
Loops and functions in rLoops and functions in r
Loops and functions in rmanikanta361
 
statistical computation using R- an intro..
statistical computation using R- an intro..statistical computation using R- an intro..
statistical computation using R- an intro..Kamarudheen KV
 
Introduction to r studio on aws 2020 05_06
Introduction to r studio on aws 2020 05_06Introduction to r studio on aws 2020 05_06
Introduction to r studio on aws 2020 05_06Barry DeCicco
 

Semelhante a Basic and logical implementation of r language (20)

Presentation R basic teaching module
Presentation R basic teaching modulePresentation R basic teaching module
Presentation R basic teaching module
 
Morel, a Functional Query Language
Morel, a Functional Query LanguageMorel, a Functional Query Language
Morel, a Functional Query Language
 
LISP: Introduction to lisp
LISP: Introduction to lispLISP: Introduction to lisp
LISP: Introduction to lisp
 
LISP: Introduction To Lisp
LISP: Introduction To LispLISP: Introduction To Lisp
LISP: Introduction To Lisp
 
Morel, a data-parallel programming language
Morel, a data-parallel programming languageMorel, a data-parallel programming language
Morel, a data-parallel programming language
 
Ejercicios de estilo en la programación
Ejercicios de estilo en la programaciónEjercicios de estilo en la programación
Ejercicios de estilo en la programación
 
R basics
R basicsR basics
R basics
 
R Basics
R BasicsR Basics
R Basics
 
R language introduction
R language introductionR language introduction
R language introduction
 
Frp2016 3
Frp2016 3Frp2016 3
Frp2016 3
 
Scala. Introduction to FP. Monads
Scala. Introduction to FP. MonadsScala. Introduction to FP. Monads
Scala. Introduction to FP. Monads
 
An Intoduction to R
An Intoduction to RAn Intoduction to R
An Intoduction to R
 
R workshop
R workshopR workshop
R workshop
 
Introduction to R
Introduction to RIntroduction to R
Introduction to R
 
Fp in scala part 2
Fp in scala part 2Fp in scala part 2
Fp in scala part 2
 
Programming in R
Programming in RProgramming in R
Programming in R
 
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docxINFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
 
Loops and functions in r
Loops and functions in rLoops and functions in r
Loops and functions in r
 
statistical computation using R- an intro..
statistical computation using R- an intro..statistical computation using R- an intro..
statistical computation using R- an intro..
 
Introduction to r studio on aws 2020 05_06
Introduction to r studio on aws 2020 05_06Introduction to r studio on aws 2020 05_06
Introduction to r studio on aws 2020 05_06
 

Mais de Md. Mahedi Mahfuj

Mais de Md. Mahedi Mahfuj (13)

Bengali optical character recognition system
Bengali optical character recognition systemBengali optical character recognition system
Bengali optical character recognition system
 
Parallel computing(1)
Parallel computing(1)Parallel computing(1)
Parallel computing(1)
 
Message passing interface
Message passing interfaceMessage passing interface
Message passing interface
 
Advanced computer architecture
Advanced computer architectureAdvanced computer architecture
Advanced computer architecture
 
Database management system chapter12
Database management system chapter12Database management system chapter12
Database management system chapter12
 
Strategies in job search process
Strategies in job search processStrategies in job search process
Strategies in job search process
 
Report writing(long)
Report writing(long)Report writing(long)
Report writing(long)
 
Job search_resume
Job search_resumeJob search_resume
Job search_resume
 
Job search_interview
Job search_interviewJob search_interview
Job search_interview
 
Big data
Big dataBig data
Big data
 
Chatbot Artificial Intelligence
Chatbot Artificial IntelligenceChatbot Artificial Intelligence
Chatbot Artificial Intelligence
 
Cloud testing v1
Cloud testing v1Cloud testing v1
Cloud testing v1
 
Distributed deadlock
Distributed deadlockDistributed deadlock
Distributed deadlock
 

Último

Organizational Transformation Lead with Culture
Organizational Transformation Lead with CultureOrganizational Transformation Lead with Culture
Organizational Transformation Lead with CultureSeta Wicaksana
 
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...rajveerescorts2022
 
Insurers' journeys to build a mastery in the IoT usage
Insurers' journeys to build a mastery in the IoT usageInsurers' journeys to build a mastery in the IoT usage
Insurers' journeys to build a mastery in the IoT usageMatteo Carbone
 
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...Dave Litwiller
 
Value Proposition canvas- Customer needs and pains
Value Proposition canvas- Customer needs and painsValue Proposition canvas- Customer needs and pains
Value Proposition canvas- Customer needs and painsP&CO
 
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service AvailableCall Girls Pune Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service AvailableDipal Arora
 
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...amitlee9823
 
Ensure the security of your HCL environment by applying the Zero Trust princi...
Ensure the security of your HCL environment by applying the Zero Trust princi...Ensure the security of your HCL environment by applying the Zero Trust princi...
Ensure the security of your HCL environment by applying the Zero Trust princi...Roland Driesen
 
John Halpern sued for sexual assault.pdf
John Halpern sued for sexual assault.pdfJohn Halpern sued for sexual assault.pdf
John Halpern sued for sexual assault.pdfAmzadHosen3
 
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best ServicesMysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best ServicesDipal Arora
 
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...Dipal Arora
 
Regression analysis: Simple Linear Regression Multiple Linear Regression
Regression analysis:  Simple Linear Regression Multiple Linear RegressionRegression analysis:  Simple Linear Regression Multiple Linear Regression
Regression analysis: Simple Linear Regression Multiple Linear RegressionRavindra Nath Shukla
 
A DAY IN THE LIFE OF A SALESMAN / WOMAN
A DAY IN THE LIFE OF A  SALESMAN / WOMANA DAY IN THE LIFE OF A  SALESMAN / WOMAN
A DAY IN THE LIFE OF A SALESMAN / WOMANIlamathiKannappan
 
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...amitlee9823
 
M.C Lodges -- Guest House in Jhang.
M.C Lodges --  Guest House in Jhang.M.C Lodges --  Guest House in Jhang.
M.C Lodges -- Guest House in Jhang.Aaiza Hassan
 
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangaloreamitlee9823
 
Monte Carlo simulation : Simulation using MCSM
Monte Carlo simulation : Simulation using MCSMMonte Carlo simulation : Simulation using MCSM
Monte Carlo simulation : Simulation using MCSMRavindra Nath Shukla
 
Monthly Social Media Update April 2024 pptx.pptx
Monthly Social Media Update April 2024 pptx.pptxMonthly Social Media Update April 2024 pptx.pptx
Monthly Social Media Update April 2024 pptx.pptxAndy Lambert
 
VIP Call Girls In Saharaganj ( Lucknow ) 🔝 8923113531 🔝 Cash Payment (COD) 👒
VIP Call Girls In Saharaganj ( Lucknow  ) 🔝 8923113531 🔝  Cash Payment (COD) 👒VIP Call Girls In Saharaganj ( Lucknow  ) 🔝 8923113531 🔝  Cash Payment (COD) 👒
VIP Call Girls In Saharaganj ( Lucknow ) 🔝 8923113531 🔝 Cash Payment (COD) 👒anilsa9823
 
Best VIP Call Girls Noida Sector 40 Call Me: 8448380779
Best VIP Call Girls Noida Sector 40 Call Me: 8448380779Best VIP Call Girls Noida Sector 40 Call Me: 8448380779
Best VIP Call Girls Noida Sector 40 Call Me: 8448380779Delhi Call girls
 

Último (20)

Organizational Transformation Lead with Culture
Organizational Transformation Lead with CultureOrganizational Transformation Lead with Culture
Organizational Transformation Lead with Culture
 
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
 
Insurers' journeys to build a mastery in the IoT usage
Insurers' journeys to build a mastery in the IoT usageInsurers' journeys to build a mastery in the IoT usage
Insurers' journeys to build a mastery in the IoT usage
 
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
 
Value Proposition canvas- Customer needs and pains
Value Proposition canvas- Customer needs and painsValue Proposition canvas- Customer needs and pains
Value Proposition canvas- Customer needs and pains
 
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service AvailableCall Girls Pune Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service Available
 
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
 
Ensure the security of your HCL environment by applying the Zero Trust princi...
Ensure the security of your HCL environment by applying the Zero Trust princi...Ensure the security of your HCL environment by applying the Zero Trust princi...
Ensure the security of your HCL environment by applying the Zero Trust princi...
 
John Halpern sued for sexual assault.pdf
John Halpern sued for sexual assault.pdfJohn Halpern sued for sexual assault.pdf
John Halpern sued for sexual assault.pdf
 
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best ServicesMysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
 
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...
 
Regression analysis: Simple Linear Regression Multiple Linear Regression
Regression analysis:  Simple Linear Regression Multiple Linear RegressionRegression analysis:  Simple Linear Regression Multiple Linear Regression
Regression analysis: Simple Linear Regression Multiple Linear Regression
 
A DAY IN THE LIFE OF A SALESMAN / WOMAN
A DAY IN THE LIFE OF A  SALESMAN / WOMANA DAY IN THE LIFE OF A  SALESMAN / WOMAN
A DAY IN THE LIFE OF A SALESMAN / WOMAN
 
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
 
M.C Lodges -- Guest House in Jhang.
M.C Lodges --  Guest House in Jhang.M.C Lodges --  Guest House in Jhang.
M.C Lodges -- Guest House in Jhang.
 
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
 
Monte Carlo simulation : Simulation using MCSM
Monte Carlo simulation : Simulation using MCSMMonte Carlo simulation : Simulation using MCSM
Monte Carlo simulation : Simulation using MCSM
 
Monthly Social Media Update April 2024 pptx.pptx
Monthly Social Media Update April 2024 pptx.pptxMonthly Social Media Update April 2024 pptx.pptx
Monthly Social Media Update April 2024 pptx.pptx
 
VIP Call Girls In Saharaganj ( Lucknow ) 🔝 8923113531 🔝 Cash Payment (COD) 👒
VIP Call Girls In Saharaganj ( Lucknow  ) 🔝 8923113531 🔝  Cash Payment (COD) 👒VIP Call Girls In Saharaganj ( Lucknow  ) 🔝 8923113531 🔝  Cash Payment (COD) 👒
VIP Call Girls In Saharaganj ( Lucknow ) 🔝 8923113531 🔝 Cash Payment (COD) 👒
 
Best VIP Call Girls Noida Sector 40 Call Me: 8448380779
Best VIP Call Girls Noida Sector 40 Call Me: 8448380779Best VIP Call Girls Noida Sector 40 Call Me: 8448380779
Best VIP Call Girls Noida Sector 40 Call Me: 8448380779
 

Basic and logical implementation of r language

  • 1. R Language INTRODUCTION: R is an open source programming language and software environment for statistical computing and graphics. The R language is widely used among statisticians and data miners for developing statistical software and data analysis. But, we are going to integrate R with Hadoop in order to manage BigData efficiently. Here, we have tried to figure out some basic commands of R followed by logical implementation using R as well. BASIC COMMANDS: GetDirectory: getwd() [ R language is case sensitive ] Assignment: Single value: s < - 3 or s = 3 [The value of s is 3] Multiple values: s < - c (1, 2, 3) [The value of s is 1, 2, 3] Or s < - c (1:3) [The value of s is 1, 2, 3]
  • 2. Mean: mean(x) [The mean of x i.e. 1, 2, 3 is 2] Variance: var(x) [The variance of x i.e.1, 2, 3 is 1] Linear Model: lm_1 < - lm(y~x) [The linear model between two variables will be shown] Graphical Representation: plot (lm_1) [The linear model will be graphically represented] Summary: summary (lm_1) [The summary of the linear model will be shown] List of variables: ls () [ The list of all variables used will be shown] Reading .csv files: read.table ( file=”sample.csv”) [Files can be read in this way, mostly csv files]
  • 3. Reading .xls files: install.packages("gdata") [ It can be done manually too. Go to Packages at the top. Select any location, preferably USA (CA 1). Then select gdata from the list. ] library(gdata) [ Use of Library for reading an Excel file. ] setwd("D:/R Statistics") [ Set working directory ] y=read.xls("iris.xls") [Read the .xls/.xlsx file that is present in the working directory. ] y [ Print the contents of the excel file. ] These were some basic knowledge on R. Now, some logical implementations are being laid down below:
  • 4. LOGICAL IMPLEMENTATION: Conditional: Example: x=5 # Creates sample data if(x!=5) { print(1) } else { print(2) } *else should be printed after “}”, not in a new line. Output: [1] 2 Ifelse: Ifelse statements operate on vectors of variable length. Syntax: ifelse(test, true_value, false_value)
  • 5. Example: x = 1:10 # Creates sample data ifelse(x<5 | x>8, x, 0) Output: [1] 1 2 3 4 0 0 0 0 9 10 For loop: Example: x=5 for(i in seq(along=x)) { if(x==5) print(1) else print(2) } Output: [1] 1 *The use of “along” prints the value for once only. At the same time, the absence of along will print the value x times likewise;
  • 6. x=5 for(i in seq(x)) { if(x==5) print(1) else print(2) } Output: [1] 1 [1] 1 [1] 1 [1] 1 [1] 1 While Loop: Example: z=0 while(z < 5) { z=z+2 print(z) } Output: [1] 2 [1] 4 [1] 6
  • 7. Apply loop: Example 1(Coloumwise operation): x= matrix(c(1:9),3,3) apply(x, 1, sum) Output: [1] 12 15 18 Example 2(Rowwise operation): x= matrix(c(1:9),3,3) apply(x, 2, sum) Output: [1] 6 15 24 lapply: Applies a function to elements in a list or a vector and returns the results in a list. Exmple: # create a list with 2 elements l = list(a = 1:10, b = 11:20) # the mean of the values in each element lapply(l, mean) Output: $a [1] 5.5 $b [1] 15.5
  • 8. # the sum of the values in each element lapply(l, sum) Output: $a [1] 55 $b [1] 155 sapply: Exmple1: li = list("klaus","martin","georg") sapply(li,toupper) Output: [1] "KLAUS" "MARTIN" "GEORG" Exmple2: # create a list with 2 elements l <- list(a = 1:10, b = 11:20) # mean of values using sapply l.mean <- sapply(l, mean) # what type of object was returned? class(l.mean) [1] "numeric" # it's a numeric vector, so we can get element "a" like this l.mean[['a']] Output: [1] 5.5
  • 9. vapply: vapply is similar to sapply, but has a pre-specified type of return value, so it can be safer (and sometimes faster) to use. Exmple: l <- list(a = 1:10, b = 11:20) # fivenum of values using vapply l.fivenum <- vapply(l, fivenum, c(Min.=0, "1st Qu."=0, Median=0, "3rd Qu."=0, Max.=0)) class(l.fivenum) [1] "matrix" # let's see it l.fivenum Output: a b Min. 1.0 11.0 1st Qu. 3.0 13.0 Median 5.5 15.5 3rd Qu. 8.0 18.0 Max. 10.0 20.0 REFERENCE: [1] http://www.r-project.org [2] http://www.cyclismo.org/tutorial/R/types.html [3] http://manuals.bioinformatics.ucr.edu/home/programming-in-r [4] http://nsaunders.wordpress.com/2010/08/20/a-brief-introduction-to-apply-in-r