Installing R - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

Installing R

Description:

Vectors have length, but no dimension length(vector) ... Can specify length of sequence and increment. rep() replicates elements ... – PowerPoint PPT presentation

Number of Views:39
Avg rating:3.0/5.0
Slides: 16
Provided by: shauna9
Category:

less

Transcript and Presenter's Notes

Title: Installing R


1
Installing R
  • CRAN http//cran.r-project.org/
  • (R homepage http//www.r-project.org/)
  • Windows 95 and later ? Base
  • rw2001.exe

2
Editors for R
  • WinEdt
  • www.winedt.com
  • Download winedt 5.3 or 5.4
  • RWinEdt package
  • http//cran.r-project.org/ ? Other ? Editing
    Support ? R-WinEdt
  • Download most recent zip file
  • Packages ? Install package(s) from local zip
    files
  • Library(RWinEdt)
  • To make automatic R? rw2001 ? etc ? Rprofile
  • Type commands, highlight, R-Paste
  • Use for comments
  • Free for about 100 uses, student license is 30
  • EMACS
  • www.xemacs.org
  • ESS package
  • Free!

3
General
  • R workspace
  • Show whats been stored ls() or objects()
  • Remove individual objects rm(a, b, etc.)
  • Clear entire workspace rm(listls())
  • Quit q() or file ? exit
  • Save workspace?
  • Where to store R files file ? change directory
  • File ? load workspace or save workspace
  • save() or save.image()
  • Up arrow repeats prior commands
  • R is case sensitive
  • gt start new command finish command
  • Customize R
  • Options()
  • Edit ? GUI preferences

4
Assignments and some basic math
  • The assignment operator consists of lt and -
    and points from the expression to the name given
    to that expression
  • x lt- 10 assigns the number 10 to the letter x
  • Assignments can be made in either direction
  • R as an over-qualified calculator
  • Log, exp
  • Mean, median, mode, max, min, sd
  • Trigonometry
  • Set operations
  • Logical operators lt, lt, gt, gt, , !

5
Vectors
  • Vectors have length, but no dimension
  • gtlength(vector)
  • c() concatenates or combines numbers inside ()
    into a vector or list
  • seq() generates sequence
  • Can specify length of sequence and increment
  • rep() replicates elements
  • gtsort(vector) sorts items in vector
  • Can use usual arithmetic and mathematical
    functions on vectors
  • Logical vectors
  • Character vectors
  • Indexing a vector
  • gtvectori

6
Matrices
  • Matrices have length and dimensions
  • gtlength(M) dim(M)
  • Generating matrices
  • By combining vectors rbind() cbind()
  • gtmatrix() command
  • Transpose
  • gtt(M)
  • Diagonal
  • gtdiag(M)
  • Inverse
  • gtsolve(M)
  • Multiplying matrices MN
  • Indexing matrices

7
Some simple functions
  • Writing a user function
  • gtfunction( argument list )expressions
  • Expressions or commands can be grouped together
    in , as they often are when writing functions.
    The value of the grouped commands is the result
    of the last expression.
  • Conditionals
  • if, else
  • Loops
  • for

8
Probability distributions
  • norm, binom, beta, cauchy, chisq, exp, f, gamma,
    geom, hyper, lnorm, logis, nbinom, t, unif,
    weibull, wilcox
  • Four prefixes
  • d for density (PDF)
  • p for distribution (CDF)
  • q for quantile (percentiles)
  • r for random generation (simulation)
  • Each distribution has arguments that need to be
    specified

9
Loading
  • Stata, SPSS, SAS files
  • Library(foreign)
  • Stata read.dta
  • SPSS read.spss
  • SAS read.xport (must first create export file in
    SAS)
  • Excel files
  • Files must be saved as comma separated value or
    .csv
  • read.table, read.csv, read.csv2 identical except
    for defaults
  • Watch the direction of /!
  • gtload(.Rdata)
  • Loading and running R programs
  • gtsource(.R)

10
Data
  • gtsummary(data)
  • gtnames(data) gtattributes(data)
  • Editing data
  • gtfix(data) or gtedit(data)
  • gtdatavar
  • gtattach(data) in order to remove need of
  • gtdetach(data)

11
NA, NaN, and Null
  • NA or Not Available
  • Applies to many modes character, numeric, etc.
  • NaN or Not a Number
  • Applies only to numeric modes
  • NULL
  • Lists with zero length

12
Lm, glm, nlm, optim
  • Linear models
  • gtlm(yx1x2)
  • Generalized linear models
  • gtglm(yx1x2, family)
  • See help(family) for family options family
    specifies error distribution
  • Non-linear minimization
  • gtnlm(f, p) where f is the function to be
    minimized and p are the starting parameters
  • Optimization
  • gtoptim(par, fn) where par are the initial values
    and fn is the function to be minimized

13
Graphics
  • gtpar() is used to set graphical options
  • mfrow and mfcol
  • gtplot(x,y)
  • gtidentify() gtabline()
  • Arguments type, point style, labels, etc.
  • Boxplot, histograms, sunflowerplots, piecharts,
    etc.
  • Saving them
  • As .pdf or .ps files
  • gtdev.off()
  • Know the current directory

14
Help!
  • gthelp(packagestats)
  • Lists functions in the specified package
  • gthelp(glm) or gt?glm
  • gthelp() for characters
  • Help ? Html help ? Search Engine Keywords
  • Potentially most helpful
  • R documentation
  • commandpackage

15
Other Resources
  • The R Manuals under Documentation at
    http//www.r-project.org
  • Mark Handcocks website at http//www.stat.washing
    ton.edu/handcock/567/links.html
  • Jonathan Barrons R resources at
    http//finzi.psych.upenn.edu/
  • Fox, John. 2002. An R and S-PLUS Companion to
    Applied Regression
  • Cori Mar is teaching an intro to R class in the
    main CSSCR lab on Wednesday from 330-5
Write a Comment
User Comments (0)
About PowerShow.com