{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

RTutorial - Brief R Tutorial June 6 2008 The best way to go...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Brief R Tutorial June 6, 2008 The best way to go through this tutorial is to first install a version of R (see installation section below) and type the commands along with the examples given. This way you can see for yourself what output each command gives. Contents 1 Introduction 2 2 R Basics - Installation, Starting, Quitting, and Objects 2 3 Entering or Reading Data Into R 2 3.1 Typing Data In Manually . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 3.2 Reading Data From a File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 3.3 Accessing Elements of Data Arrays, Vectors, or Matrices . . . . . . . . . . . . . . . . . . . . . 4 3.4 Determining Sizes of Data Structures/Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 4 Basic R Commands You Should Know 4 5 Statistical Commands You Should Know 4 6 Writing Your Own Functions and Sourcing Code 5 6.1 Writing a Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 6.2 For and While Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 6.3 Logical Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 6.4 Sourcing Code and Setting the Working Directory . . . . . . . . . . . . . . . . . . . . . . . . 6 7 Graphics 7 7.1 Creating a pdf or ps File of an R Figure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 8 Writing Output To A File 7 9 Installing Packages 8 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
1 Introduction R is a statistical programming language that provides many built in functions for performing statistical analysis. R is also flexible enough to allow users to write their own functions and source code written in a text editor such as NotePad or Emacs. The advantage to learning R is that R is very easy to learn and easy to use. However, R is quite slow when doing heavy computational work (such as Bayesian algorithms) and so using R for heavy computing is not recommended. This tutorial provides a very brief introduction to how to use R. This document will go through some of the most commonly used R functions but will in no way cover all of the functions in R. To learn advanced R functions, you should use Internet searches with the key word CRAN which stands for Comprehensive R Archive Network. Using the key word CRAN in addition to other key words about the function you are looking for will generally produce a lot of results. If you forget the specific syntax for the R functions listed in this tutorial, you can simply type ?function and R will return the documentation for function which will provide almost all the necessary information for using function . As an example, typing ?qnorm will return the documentation for the R function qnorm . Alternatively you can use help(functionname) which does the same thing that ?functionname does. 2 R Basics - Installation, Starting, Quitting, and Objects R can be downloaded and installed for free from the website http://cran.r-project.org . This web page provides detailed instructions for installing R on any operating system. If you are using the department computers, you do not need to install R as it has already been installed for you. Accessing R is different for every operating system. For windows users, simply double click the R icon that is created after installation. For Mac users, you can double click the R icon under your Applications menu. On Linux and the department computers, in the terminal window (if you don’t know what a terminal window is then please read the Linux tutorial) simply type R at the command prompt and R will be opened within the terminal window.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}