SlideShare ist ein Scribd-Unternehmen logo
1 von 10
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Andere mochten auch (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)
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von Md. Mahedi Mahfuj

Mehr von 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
 

Kürzlich hochgeladen

Creating Low-Code Loan Applications using the Trisotech Mortgage Feature Set
Creating Low-Code Loan Applications using the Trisotech Mortgage Feature SetCreating Low-Code Loan Applications using the Trisotech Mortgage Feature Set
Creating Low-Code Loan Applications using the Trisotech Mortgage Feature SetDenis Gagné
 
RSA Conference Exhibitor List 2024 - Exhibitors Data
RSA Conference Exhibitor List 2024 - Exhibitors DataRSA Conference Exhibitor List 2024 - Exhibitors Data
RSA Conference Exhibitor List 2024 - Exhibitors DataExhibitors Data
 
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
 
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
 
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
 
Cracking the Cultural Competence Code.pptx
Cracking the Cultural Competence Code.pptxCracking the Cultural Competence Code.pptx
Cracking the Cultural Competence Code.pptxWorkforce Group
 
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
 
Grateful 7 speech thanking everyone that has helped.pdf
Grateful 7 speech thanking everyone that has helped.pdfGrateful 7 speech thanking everyone that has helped.pdf
Grateful 7 speech thanking everyone that has helped.pdfPaul Menig
 
Event mailer assignment progress report .pdf
Event mailer assignment progress report .pdfEvent mailer assignment progress report .pdf
Event mailer assignment progress report .pdftbatkhuu1
 
Boost the utilization of your HCL environment by reevaluating use cases and f...
Boost the utilization of your HCL environment by reevaluating use cases and f...Boost the utilization of your HCL environment by reevaluating use cases and f...
Boost the utilization of your HCL environment by reevaluating use cases and f...Roland Driesen
 
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
 
Mondelez State of Snacking and Future Trends 2023
Mondelez State of Snacking and Future Trends 2023Mondelez State of Snacking and Future Trends 2023
Mondelez State of Snacking and Future Trends 2023Neil Kimberley
 
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
 
9599632723 Top Call Girls in Delhi at your Door Step Available 24x7 Delhi
9599632723 Top Call Girls in Delhi at your Door Step Available 24x7 Delhi9599632723 Top Call Girls in Delhi at your Door Step Available 24x7 Delhi
9599632723 Top Call Girls in Delhi at your Door Step Available 24x7 DelhiCall Girls in Delhi
 
Pharma Works Profile of Karan Communications
Pharma Works Profile of Karan CommunicationsPharma Works Profile of Karan Communications
Pharma Works Profile of Karan Communicationskarancommunications
 
Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...
Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...
Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...Lviv Startup Club
 
A305_A2_file_Batkhuu progress report.pdf
A305_A2_file_Batkhuu progress report.pdfA305_A2_file_Batkhuu progress report.pdf
A305_A2_file_Batkhuu progress report.pdftbatkhuu1
 
HONOR Veterans Event Keynote by Michael Hawkins
HONOR Veterans Event Keynote by Michael HawkinsHONOR Veterans Event Keynote by Michael Hawkins
HONOR Veterans Event Keynote by Michael HawkinsMichael W. Hawkins
 
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
 
7.pdf This presentation captures many uses and the significance of the number...
7.pdf This presentation captures many uses and the significance of the number...7.pdf This presentation captures many uses and the significance of the number...
7.pdf This presentation captures many uses and the significance of the number...Paul Menig
 

Kürzlich hochgeladen (20)

Creating Low-Code Loan Applications using the Trisotech Mortgage Feature Set
Creating Low-Code Loan Applications using the Trisotech Mortgage Feature SetCreating Low-Code Loan Applications using the Trisotech Mortgage Feature Set
Creating Low-Code Loan Applications using the Trisotech Mortgage Feature Set
 
RSA Conference Exhibitor List 2024 - Exhibitors Data
RSA Conference Exhibitor List 2024 - Exhibitors DataRSA Conference Exhibitor List 2024 - Exhibitors Data
RSA Conference Exhibitor List 2024 - Exhibitors Data
 
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
 
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
 
Monte Carlo simulation : Simulation using MCSM
Monte Carlo simulation : Simulation using MCSMMonte Carlo simulation : Simulation using MCSM
Monte Carlo simulation : Simulation using MCSM
 
Cracking the Cultural Competence Code.pptx
Cracking the Cultural Competence Code.pptxCracking the Cultural Competence Code.pptx
Cracking the Cultural Competence Code.pptx
 
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
 
Grateful 7 speech thanking everyone that has helped.pdf
Grateful 7 speech thanking everyone that has helped.pdfGrateful 7 speech thanking everyone that has helped.pdf
Grateful 7 speech thanking everyone that has helped.pdf
 
Event mailer assignment progress report .pdf
Event mailer assignment progress report .pdfEvent mailer assignment progress report .pdf
Event mailer assignment progress report .pdf
 
Boost the utilization of your HCL environment by reevaluating use cases and f...
Boost the utilization of your HCL environment by reevaluating use cases and f...Boost the utilization of your HCL environment by reevaluating use cases and f...
Boost the utilization of your HCL environment by reevaluating use cases and f...
 
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
 
Mondelez State of Snacking and Future Trends 2023
Mondelez State of Snacking and Future Trends 2023Mondelez State of Snacking and Future Trends 2023
Mondelez State of Snacking and Future Trends 2023
 
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...
 
9599632723 Top Call Girls in Delhi at your Door Step Available 24x7 Delhi
9599632723 Top Call Girls in Delhi at your Door Step Available 24x7 Delhi9599632723 Top Call Girls in Delhi at your Door Step Available 24x7 Delhi
9599632723 Top Call Girls in Delhi at your Door Step Available 24x7 Delhi
 
Pharma Works Profile of Karan Communications
Pharma Works Profile of Karan CommunicationsPharma Works Profile of Karan Communications
Pharma Works Profile of Karan Communications
 
Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...
Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...
Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...
 
A305_A2_file_Batkhuu progress report.pdf
A305_A2_file_Batkhuu progress report.pdfA305_A2_file_Batkhuu progress report.pdf
A305_A2_file_Batkhuu progress report.pdf
 
HONOR Veterans Event Keynote by Michael Hawkins
HONOR Veterans Event Keynote by Michael HawkinsHONOR Veterans Event Keynote by Michael Hawkins
HONOR Veterans Event Keynote by Michael Hawkins
 
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...
 
7.pdf This presentation captures many uses and the significance of the number...
7.pdf This presentation captures many uses and the significance of the number...7.pdf This presentation captures many uses and the significance of the number...
7.pdf This presentation captures many uses and the significance of the number...
 

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