You can also Email your R problems to help@tutorteddy.com or call toll free 866-930-6363 for R help.

TutorTeddy offers R help. We help you with your R assignment help questions.

R Homework Help

  • What is R?
  • R is a very powerful tool for analysing, visualizing, and reporting of statistical data. It is an Open Source software and is very interactive. Unlike traditional language like C++ where we have to write the entire code to see the results, the results in R will be reflected for one command at a time.

  • Where is it used?
  • The language is used mainly by statisticians and data miners. It is used in the banking sector, food start-ups, hospitals, real estate developers, insurance companies, online advertising, and pharmaceuticals. It is also popular in the advanced machine learning platform.

  • The R Environment:
  • R offers data computation and graphical representation of data. Big data can be handled through this software.

    The following standard R interface is displayed when we open the R software:

    R Help

    Various Integrated Development Environment (IDEs) are built for R. Among all these IDEs, RStudio is the most popular one.

  • R Studio:
  • RStudio was created by the team led by JJ Allaire. It is available for Windows, Mac, and Linux. RStudio is an improvement over the standard R and its interface looks like the following figure:

    R Help

  • RStudio Projects:
  • A Project is a primary feature in RStudio. It is a collection of files. To view projects, we need to click on File>>New Project.

    Clicking on the above will result in the following project creation:

    R Help

    We need to choose any one of the three options to start a project.

  • Installing Packages:
  • There are many ways to install packages in R. In RStudio, we can access the packages tab by clicking on it. The following figure shows the RStudio Packages pane.

    R Help

    Another way to install packages is to write a simple command in console:

  • >install.packages("cluster")
    • Basic symbols in R:
    • In R, we use "<-" symbol to assign a value to a variable. That is if we assign 2 to x we would write the command as x<-2.

      The symbol ,"==" denotes equals to. And "!=" denotes not equal to.

    • Data Types in R:
      1. Numeric Data: It indicates integers and decimals that may be positive or negative or zero. In R numeric and integer both indicate numeric data
      2. Character Data: Its string data type. character and factor both represent character data in R
      3. Dates Data: The type of data is the date, where Date and POSICXct are widely used functions in R
      4. Logical: Logical is representing data as TRUE OR FALSE. TRUE is 1 and FALSE is 0.
    • Vectors and Matrices:
    • A Vector is a collection of the same type of elements. In R, a vector is written as c(1,2,3,4). It plays a very important role in R. The following command shows us how to write a vector in R:

      > x=c(1,2,3,4)

      >x

      [1] 1 2 3 4

      From the above, we see if we write the command x=c(1,2,3,4) and then write x, the values 1,2,3,4 would come as the result.

      Matrices are a very important structure in Mathematics and are often used in Statistics. We use the function matrix to construct a matrix in R. nrow, ncol, and dim functions in R denotes the number of rows, the number of columns, and the dimension of matrix respectively The following command shows us how to write a matrix in R:

      > #create a matrix of order 2*5

      > A <-matrix (1:10,nrow=2)

      > A

      [,1] [,2] [,3] [,4] [,5]

      [1,]

      1 3 5

      7 9

      [2,]

      2 4 6

      8 10

      > # create another matrix of order 2*5

      > B<-matrix (31:40,nrow=2)

      > B

      [,1] [,2] [,3] [,4] [,5]

      [1,]

      31 33 35

      37 39

      [2,]

      32 34 36

      38 40

      > nrow(A)

      [1] 2

      > ncol(B)

      [1] 5

      > dim(B)

      [1] 2 5

      > # Add the two matrices

      > A+B

      [,1] [,2] [,3] [,4] [,5]

      [1,]

      32 36 40

      44 48

      [2,]

      34 38

      42 46 50

      > # Multiply the two matrices

      > A*B

      [,1] [,2] [,3] [,4] [,5]

      [1,]

      31 99 175

      259 351

      [2,]64 136

      216 304 400

      In the above, # is used to write a comment. Often when we have many codes, we use comments to make the reader understand what the code means. 1:10 means numbers from 1 to 10 and 31:40 means numbers from 31 to 40. Lastly, we have performed Matrix addition and multiplication.

    • Data Frames and Lists:
    • Data Frames is a vital part in R and is written as data.frames. In data.frames, each column is a vector having the same length. The following command in R shows how to write a Data Frame:

      > x<-50:41

      > y<--8:1

      > z<-c("Oranges","Pineapples","Blueberry","Cherries","Avocados", "Bananas","Apples","Grapes","Litchis","Mangoes")

      > DFrame<-data.frame(x,y,z)

      > DFrame

      x y z

      1 50 -8 Oranges

      2 49 -7 Pineapples

      3 48 -6 Blueberry

      4 47 -5 Cherries

      5 46 -4 Avocados

      6 45 -3 Bananas

      7 44 -2 Apples

      8 43 -1 Grapes

      9 42 0 Litchis

      10 41 1 Mangoes

      From the above, we see data.frames allow columns to have a different type of data. The first two columns are numeric type, while the last column is of character type.

    • Lists:
    • The List acts a container that holds arbitrary objects of the same or different types of data. That is to say, a list can contain all numerics or all characters or a mix of these two types of data. The function List is used to denote List in R. The following command in R shows how to write a list in R:

      > #create a list of a single element, where it is a vector having 2 elements

      > list(c(1,2))

      [[1]]

      [1] 1 2

      > #create a list of two element, one is a 3 element vector, and 2nd element is 4 element vector

      > list(c(1,2,5),45:48)

      [[1]]

      [1] 1 2 5

      [[2]]

      [1] 45 46 47 48

    • Reading Data into R:
    • R can read data from CSVs, SQL, SPSS, SAS, Minitab, Stata, etc. The following are the functions that are used for reading data from different software:

      Type/Name of Software

      Functions in R

      Reading CSVs

      read.table

      Reading SPSS

      read.spss

      Reading SAS

      read.ssd

      Reading Minitab

      read.mtp

    • Head and Tail in R:
    • The Head function shows the first few rows of a matrix or data frames, whereas the Tail function shows the last few rows of them. The Head function is written as "head", while the Tail function is written as "tail".

    • Graphical Options:
    • There are many options to create statistical graphs in R. For advance graphical features, we need to install and load ggplot2.

    • Control Statements and Loops:
      • If and Else
      • if and else statements are used when we need to check if something is TRUE, then we need to perform an action, otherwise we do not perform it. The following shows how to write such functions in R:

        > #create the function

        > check.bool<-function(x)

        + {

        + if(x==2){

        # if input is equal to 2, print How are you?

        + print("How are you?")

        + }

        + else{

        +

        + # otherwise print who are you?

        + print("Who are you?")

        + }

        + }

      • For loops
      • For loop is used as an index that gets repeated or iterated. The following shows how a for loop works in R:

        > for (i in 25:30)

        + {

        + print(i)

        + }

        [1] 25

        [1] 26

        [1] 27

        [1] 28

        [1] 29

        [1] 30

      • While loops
      • While loops are used to run the code as long as the conditions are proved to be true. The following shows an illustration for a while loop:

        > x<-2

        > while(x<=10)

        + {

        + print(x)

        + x=x+1

        + }

        [1] 2

        [1] 3

        [1] 4

        [1] 5

        [1] 6

        [1] 7

        [1] 8

        [1] 9

        [1] 10

    • cbind and rbind:
    • The cbind function in R is used to combine data frames, matrices, and vectors by columns. The rbind function does the same operation as above by using the rows instead of the columns.

    • Analyzing Data in R:
    • The following are some of the Statistical analyses that can be performed in R:

      • Basic Statistics:
      • In order to find the descriptive statistics of the data in R, we use mean for finding mean, median for finding median, sd for finding standard deviations, cor for correlation and so on. Following is an example of Basic Statistics analysis in R:

        > x=c(52,100,43,86,121,85,46,12,91,100,45,47,136,161,25,112)

        > summary(x)

        Min. 1st Qu. Median Mean 3rd Qu. Max.

        12.00 45.75 85.50 78.88 103.00 161.00

        > quantile(x)

        0% 25% 50% 75% 100%

        12.00 45.75 85.50 103.00 161.00

        > mean(x)

        [1] 78.875

        > mode(x)

        [1] "numeric"

        > sd(x)

        [1] 42.13925

      • Linear Model:
      • Linear regression models can be analysed in R using function "lm". For ANOVA we use the function "aov". Following is an example showing a simple linear analysis in R:

        > ageLM<-lm(age~circumference,data=Orange)

        > ageLM

        Call:

        lm(formula = age ~ circumference, data = Orange)

        Coefficients:

        (Intercept) circumference

        16.604 7.816

        > summary(ageLM)

        Call:

        lm(formula = age ~ circumference, data = Orange)

        Residuals:

        Min 1Q Median 3Q Max

        -317.88 -140.90 -17.20 96.54 471.16

        Coefficients:

        Estimate Std. Error t value Pr(>|t|)

        (Intercept) 16.6036 78.1406 0.212 0.833

        circumference 7.8160 0.6059 12.900 1.93e-14 ***

        Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

        Residual standard error: 203.1 on 33 degrees of freedom

        Multiple R-squared: 0.8345, Adjusted R-squared: 0.8295

        F-statistic: 166.4 on 1 and 33 DF, p-value: 1.931e-14

      • Generalized Linear Model:
      • Sometimes when linear regression can't be fitted, we need to use the generalized model. We use glm function for such cases. Logistic regression, Poisson regression, etc. are some of the examples of the generalized linear model. Following is an illustration of running a generalized linear model in R:

        > counts <- c(18,17,15,20,10,20,25,13,12)

        > outcome <- gl(3,1,9)

        > treatment <- gl(3,3)

        > print(d.AD <- data.frame(treatment, outcome, counts))

        treatment outcome counts

        1 1

        1 18

        2 1

        2 17

        3 1

        3 15

        4 2

        1 20

        5 2

        2 10

        6 2

        3 20

        7 3

        1 25

        8 3

        2 13

        9 3

        3 12

        > glm.D93 <- glm(counts ~ outcome + treatment, family = poisson())

        > anova(glm.D93)

        Analysis of Deviance Table

        Model: poisson, link: log

        Response: counts

        Terms added sequentially (first to last)

        Df Deviance Resid. Df Resid. Dev

        NULL 8 10.5814

        outcome 2

        5.4523 6 5.1291

        treatment 2

        0.0000 4 5.1291

        > summary(glm.D93)

        Call:

        glm(formula = counts ~ outcome + treatment, family = poisson())

        Deviance Residuals:

        1

        2 3 4 5 6 7 8 9

        -0.67125 0.96272

        -0.16965 -0.21999 -0.95552

        1.04939 0.84715 -0.09167

        -0.96656

        Coefficients:

        Estimate Std. Error z value Pr(>|z|)

        (Intercept) 3.045e+00

        1.709e-01 17.815 <2e-16 ***

        outcome2 -4.543e-01

        2.022e-01 -2.247 0.0246 *

        outcome3 -2.930e-01

        1.927e-01 -1.520 0.1285

        treatment2 1.338e-15

        2.000e-01 0.000 1.0000

        treatment3 1.421e-15

        2.000e-01 0.000 1.0000

        Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

        (Dispersion parameter for poisson family taken to be 1)

        Null deviance: 10.5814 on 8

        degrees of freedom

        Residual deviance: 5.1291 on 4

        degrees of freedom

        AIC: 56.761

        Number of Fisher Scoring iterations: 4

      • Time Series Analysis:
      • Basic and advanced time series analysis can be carried out in R. For instance if we want to create time-series objects we use the function ts. The following is one such example:

        > ts(1:10, frequency = 4, start = c(1959, 2)) # 2nd Quarter of 1959

        Qtr1 Qtr2 Qtr3 Qtr4

        1959 1

        2 3

        1960 4

        5 6 7

        1961 8

        9 10

        > print( ts(1:10, frequency = 7, start = c(12, 2)), calendar = TRUE)

        p1 p2 p3 p4 p5 p6 p7

        12 1

        2 3 4

        5 6

        13 7

        8 9 10

        > # print.ts(.)

        > ## Using July 1954 as start date:

        > gnp <- ts(cumsum(1 + round(rnorm(100), 2)),

        + start = c(1954, 7), frequency = 12)

        > plot(gnp) # using 'plot.ts' for time-series plot

        We get the following plot as the output in Plot area of RStudio:

        R Help

Our help:

R can thus handle complicated data and thus helping the statisticians or the researchers with their analysis. Our R homework help will help you to write complex R codes.

For those of you requiring professional help for understanding your R help, you can come to us. Our qualified tutors are fully equipped to offer you assistance in explaining R homework problems.

This assistance is made available to you through solutions which are provided in a step-by-step manner.

For R help, there are numerous highly qualified tutors with many years of experience in this field. Once you send us your problem, we can forward them to our tutors for reviews.

TutorTeddy.com & Boston Predictive Analytics

[ Email your Statistics or Math problems to help@tutorteddy.com (camera phone photos are OK) ]


Boston Office (Near MIT/Kendall 'T'):
Cambridge Innovation Center,
One Broadway, 14th Floor,
Cambridge, MA 02142,
Phone: 617-395-8864
866-930-6363WhatsApp


Dallas Office (Near Galleria):
15950 Dallas Parkway,
Suite 400,
Dallas, TX 75248,
Phone: 617-395-8864
866-930-6363WhatsApp

Privacy Policy

Contact

*Restrictions Apply (See TOS below)