R SOFTWARE: AN OVERVIEW AND DESCRIPTIVE STATISTICS

R SOFTWARE: AN OVERVIEW AND DESCRIPTIVE STATISTICS A. Dhandapani NAARM, Rajendranagar, Hyderabad [email protected] Introduction R is a statist...
16 downloads 0 Views 61KB Size
R SOFTWARE: AN OVERVIEW AND DESCRIPTIVE STATISTICS A. Dhandapani NAARM, Rajendranagar, Hyderabad [email protected] Introduction R is a statistical computing environment having facilities for data manipulation, calculation, graphical display etc. R is also a free implementation of S language, which was developed for statistical computing and graphics by John Chambers of Bell Labs. A commercial version of S is also available as S+® from Insightful Co. R was developed initially by Ross Ihaka and Robert Gentleman. R is developed as open source software and available free for use. Installation of R R package can be downloaded from the R project site, www.r-project.org . The current version is 2.15.0. R is also available for wide variety of operating systems such as Microsoft ®Windows®, Mac OS X and Unix X11 (Linux). There are several additional packages available which can also be downloaded for free. To install R package in MS-Windows ® platform, download the latest version of R from the following location: http://cran.r-project.org/bin/windows/base/. The file is called R-2.15.0win.exe (~48 MB). Run this file and follow the instruction in the screen to install it. To run the software, go to Start  Programs  RR-2.15.0 and click. The default R screen should appear with the title R GUI/R console with a > symbol in Red colour and red blinking cursor. Interaction with R software can be carried out with this command prompt. Getting Help Complete help files in HTML and PDF forms are available. There is an excellent introduction to R package can be found in Help  Manuals (in pdf) “A introduction to R”. Several other documentations are also given at the end of this lecture note. To get help on a particular command/function etc., type help (command name). For example, to get help on function ‘mean’, type in the command prompt(>) >help(mean) This will open the help file with the page containing the description of the function mean. In this lecture note, all R commands and corresponding outputs are given as shaded text to differentiate the normal texts. It should be noted that R is case-sensitive, i.e. typing Help(mean), would get an error message, > Help(mean) Error: could not find function "Help"

R Software: An Overview and Descriptive Statistics

> Packages The strength of R comes from the optional packages available (again freely). The complete list is available at R-Project website. Packages can be installed either by using the Install Package option within R or download the packages from R-Project website and using the option, install from local Zip files. Packages are to be loaded before using through Load Package option. For more details, refer R Help system. Using R R can also be used as a calculator. For example, > 2+(3*2) [1] 8 To compute, say roots of the equation, x 2  3 x  2 , the following commands can be used: > (3+sqrt(-3*-3-(4*1*2)))/(2*1) [1] 2 > (3-sqrt(-3*-3-(4*1*2)))/(2*1) [1] 1 In the above example, a built-in function sqrt() is used to evaluate the square root of a number. Try to compute the square root of a negative number, > sqrt(-4) [1] NaN Warning message: In sqrt(-4) : NaNs produced R produces a warning message saying that the result is not a number (NaN). Workspace and History To exist R at the end, type q(). A warning message will be displayed, whether to save the workspace or not. If workspace is saved, R remembers all the objects/variables etc used /created during the particular session. The saved workspace can be loaded into R next time and one can continue working. Thus, one need not recreate again all the objects/variables. Also, the commands entered during a session can be saved as history. This will be useful to store all the relevant commands to run a particular problem in a file and can be run directly with out typing the commands again and again. Data Types Vector In any programming environment, the foremost thing is to learn the various data types supported. Also, in statistics, data comes in various forms such as numeric, categorical,

R Software: An Overview and Descriptive Statistics

multivariate, time series etc. R supports various data types such as numeric vectors/matrices; character vectors; categorical, logical etc. Simplest structure is a numeric vector, which stores ordered collection of numbers of any specific dimension. To begin with, create a vector, say a with 4 entries 1,0,-1 & 3, i.e. a  1 0 1 3 , in R use a

Suggest Documents