R-beginner_tutorial - Introduction Basic Syntax R Studio R Commander Having Some\"Fun with R R Tutorial For Beginners Statistics and Actuarial Science

R-beginner_tutorial - Introduction Basic Syntax R Studio R...

This preview shows page 1 - 10 out of 47 pages.

Introduction Basic Syntax R Studio R Commander Having Some "Fun" with R R Tutorial - For Beginners Statistics and Actuarial Science FALL 2012 Statistics and Actuarial Science 1/ 47
Introduction Basic Syntax R Studio R Commander Having Some "Fun" with R Outline 1 Introduction 2 Basic Syntax 3 R Studio 4 R Commander 5 Having Some "Fun" with R Statistics and Actuarial Science 2/ 47
Introduction Basic Syntax R Studio R Commander Having Some "Fun" with R Introduction What is R? R is a powerful, free, open-source programming language and software environment for statistical analysis and data visualization. Why use R? Similar syntax to the S language (a popular statistical language for research), but free - as such, it is used in many Statistics courses at U of W. Basic functionality can be extended via packages . Download R at Statistics and Actuarial Science 3/ 47
Introduction Basic Syntax R Studio R Commander Having Some "Fun" with R Companies Using R Facebook to analyze status updates or to visualize the "locality of friendship": blog.revolutionanalytics.com/2010/12/facebooks-social-network-graph.html Google to predict economic activity. Mozilla to analyze web activity: Statistics and Actuarial Science 4/ 47
Introduction Basic Syntax R Studio R Commander Having Some "Fun" with R Outline 1 Introduction 2 Basic Syntax 3 R Studio 4 R Commander 5 Having Some "Fun" with R Statistics and Actuarial Science 5/ 47
Introduction Basic Syntax R Studio R Commander Having Some "Fun" with R Basic Syntax Comments # Any words after a number sign is a comment and # is not executed in R. Setting a variable n to the value 10 n = 5 Square roots and Exponentiating sqrt(n) # find the square root of ’n’ ## [1] 2.236 exp(n) # find e^n ## [1] 148.4 Statistics and Actuarial Science 6/ 47
Introduction Basic Syntax R Studio R Commander Having Some "Fun" with R Vectors Create a vector ’x1’ containing the values 1, 2, and 3. x1 = c(1, 2, 3) Create a vector of ’n’ zero’s. x2 = rep(0, n) Store the values of the vectors x1 and x2 in the vector x3. It is equivalent to the command x3 = c(1, 2, 3, 0, 0, 0, 0, 0) x3 = c(x1, x2) Add the 2nd element of x3 to the 1st element of x3 and store it as the 1st element of x3 x3[1] = x3[1] + x3[2] # NOTE: the vector index starts at 1 and not 0. Display x3 x3 ## [1] 3 2 3 0 0 0 0 0 Statistics and Actuarial Science 7/ 47
Introduction Basic Syntax R Studio R Commander Having Some "Fun" with R Vectors (Continued) Create and display a vector x4 whose elements form an arithmetic progression x5 = seq(from = 0.5, to = 4, by = 0.5) x5 ## [1] 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 Access the first and third elements of x5 x5[c(1, 3)] ## [1] 0.5 1.5 Elementwise addition of x3 and x5 x3 + x5 ## [1] 3.5 3.0 4.5 2.0 2.5 3.0 3.5 4.0 Statistics and Actuarial Science 8/ 47
Introduction Basic Syntax R Studio R Commander Having Some "Fun" with R Summary Statistics Create a vector y of 8 simulations of a N ( 0 , 1 ) r.v.

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture