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

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

IntroductionBasic SyntaxR StudioR CommanderHaving Some "Fun" with RR Tutorial - For BeginnersStatistics and Actuarial ScienceFALL 2012Statistics and Actuarial Science1/ 47
IntroductionBasic SyntaxR StudioR CommanderHaving Some "Fun" with ROutline1Introduction2Basic Syntax3R Studio4R Commander5Having Some "Fun" with RStatistics and Actuarial Science2/ 47
IntroductionBasic SyntaxR StudioR CommanderHaving Some "Fun" with RIntroductionWhat is R?R is a powerful, free, open-source programming language andsoftware environment for statistical analysis and datavisualization.Why use R?Similar syntax to the S language (a popular statisticallanguage for research), but free - as such, it is used inmany Statistics courses at U of W.Basic functionality can be extended viapackages.Download R atStatistics and Actuarial Science3/ 47
IntroductionBasic SyntaxR StudioR CommanderHaving Some "Fun" with RCompanies Using RFacebookto analyze status updates or to visualize the"locality of friendship":blog.revolutionanalytics.com/2010/12/facebooks-social-network-graph.htmlGoogleto predict economic activity.Mozillato analyze web activity:Statistics and Actuarial Science4/ 47
IntroductionBasic SyntaxR StudioR CommanderHaving Some "Fun" with ROutline1Introduction2Basic Syntax3R Studio4R Commander5Having Some "Fun" with RStatistics and Actuarial Science5/ 47
IntroductionBasic SyntaxR StudioR CommanderHaving Some "Fun" with RBasic SyntaxComments# Any words after a number sign is a comment and# is not executed in R.Setting a variable n to the value 10n = 5Square roots and Exponentiatingsqrt(n)# find the square root of ’n’## [1] 2.236exp(n)# find e^n## [1] 148.4Statistics and Actuarial Science6/ 47
IntroductionBasic SyntaxR StudioR CommanderHaving Some "Fun" with RVectorsCreate 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. Itis 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 andstore it as the 1st element of x3x3[1] = x3[1] + x3[2]# NOTE: the vector index starts at 1 and not 0.Display x3x3## [1] 3 2 3 0 0 0 0 0Statistics and Actuarial Science7/ 47
IntroductionBasic SyntaxR StudioR CommanderHaving Some "Fun" with RVectors (Continued)Create and display a vector x4 whose elements form anarithmetic progressionx5 = 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.0Access the first and third elements of x5x5[c(1, 3)]## [1] 0.5 1.5Elementwise addition of x3 and x5x3 + x5## [1] 3.5 3.0 4.5 2.0 2.5 3.0 3.5 4.0Statistics and Actuarial Science8/ 47
IntroductionBasic SyntaxR StudioR CommanderHaving Some "Fun" with RSummary StatisticsCreate a vector y of 8 simulations of aN(0,1)r.v.

Upload your study docs or become a

Course Hero member to access this document

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 47 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Spring
Professor
McKay
Tags
Actuarial Science, Statistics, Binomial distribution, Commander

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture