Uma breve introdução ao R

Transcrição

Uma breve introdução ao R
Uma breve introdução ao R
Antonio Augusto Franco Garcia
16 de março de 2013
1
Primeiras Ideias
Uma calculadora de luxo:
(10 + 2) * 5
## [1] 60
Objetos:
n <- 15
n <- 10 + 2
Ajuda?
`?`(plot)
Algumas operações úteis:
x <- 1:30
seq(1, 5, 0.5)
## [1] 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0
c(1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5)
## [1] 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0
z <- scan()
x <- 1:5
x[3]
## [1] 3
x <- matrix(1:6, 2, 3)
x
##
[,1] [,2] [,3]
## [1,]
1
3
5
## [2,]
2
4
6
x[1, 2]
## [1] 3
x[, 3]
## [1] 5 6
1
2
Leitura de Dados
Planilhas, etc.
mydata <- read.table("data.dat")
Internet:
nba <- read.csv("http://datasets.flowingdata.com/ppg2008.csv", sep = ",")
3
3.1
Gráficos
Funções básicas
x <- rnorm(1000)
hist(x)
2
100
0
50
Frequency
150
200
Histogram of x
−3
−2
−1
0
x
x <- 1:10
y <- rnorm(10)
plot(x, y)
3
1
2
3
●
2
●
y
1
●
●
●
●
0
●
●
−1
●
●
2
4
6
x
3.2
Funções mais elaboradas
`?`(rnorm)
`?`(rbinom)
x <- rnorm(10)
y <- rnorm(10)
plot(x, y)
4
8
10
●
●
1
●
●
●
●
0
●
●
−2
−1
y
●
●
−0.5
0.0
0.5
1.0
1.5
2.0
x
Alterando algumas opções
plot(x, y, xlab = "Ten random values", ylab = "Ten other values", xlim = c(-2, 2), ylim = c(-2,
2), pch = 22, col = "red", bg = "yellow", bty = "l", tcl = 0.4, main = "How to customize a plot with
las = 1, cex = 1.5)
5
How to customize a plot with R
2
Ten other values
1
0
−1
−2
−2
−1
0
1
2
Ten random values
demo(graphics)
# Heatmap, exemplo (from flowingdata)
nba <- nba[order(nba$PTS), ]
row.names(nba) <- nba$Name
nba <- nba[, 2:20]
nba_matrix <- data.matrix(nba)
nba_heatmap <- heatmap(nba_matrix, Rowv = NA, Colv = NA, col = cm.colors(256), scale = "column",
margins = c(5, 10))
6
Não deixe de conhecer o excepcional pacote ggplot2!
4
Gravação
`?`(write.table)
5
Instalação de Pacotes
install.packages()
7
TO
BLK
STL
AST
TRB
DRB
ORB
X3PP
X3PA
X3PM
FTP
FTA
FTM
FGP
FGA
FGM
PTS
MIN
G
Dwyane Wade
LeBron James
Kobe Bryant
Dirk Nowitzki
Danny Granger
Kevin Durant
Kevin Martin
Al Jefferson
Carmelo Anthony
Chris Paul
Chris Bosh
Brandon Roy
Antawn Jamison
Tony Parker
Joe Johnson
Amare Stoudemire
Devin Harris
Michael Redd
David West
Vince Carter
Caron Butler
Zachary Randolph
Ben Gordon
Stephen Jackson
Dwight Howard
Paul Pierce
Al Harrington
Yao Ming
Jamal Crawford
Jason Terry
Richard Jefferson
Deron Williams
Tim Duncan
Monta Ellis
Pau Gasol
Rudy Gay
Andre Iguodala
Corey Maggette
O.J. Mayo
Richard Hamilton
John Salmons
Ray Allen
LaMarcus Aldridge
Josh Howard
Shaquille O'neal
Maurice Williams
Chauncey Billups
Rashard Lewis
Allen Iverson
Nate Robinson
library("fortunes")
fortune()
##
## The only people who should use the assign function are those who fully understand why you
## should never use the assign function.
##
-- Greg Snow
##
R-help (July 2009)
install.packages("onemap")
Referência sobre o OneMap: Margarido et al. (2007).
6
Sites interessantes
• http://cran.r-project.org/
• http://www.rseek.org/
Livros e apostilas: gosto muito de Dalgaard (2008), Matloff (2011) e Verzani (2001).
Referências
Dalgaard, P., 2008 Introductory Statistics with R. Springer, New York, second edition.
Margarido, G. R. A., A. P. Souza, and A. A. F. Garcia, 2007 OneMap: software for genetic mapping in
outcrossing species. Hereditas 144: 78–79.
Matloff, N., 2011 The Art of R Programming. No Starch Press, Inc., San Francisco, CA, first edition.
Verzani, J., 2001 simpleR – Using R for Introductory Statistics. Online.
8

Documentos relacionados

NATIONAL BASKETBALL ASSOCIATION

NATIONAL BASKETBALL ASSOCIATION Kevin Durant Andre Iguodala Russell Westbrook Deron Williams Kevin Love James Harden Anthony Davis

Leia mais

Statistical Computing 1, Stat 590 Fall 2015

Statistical Computing 1, Stat 590 Fall 2015 Part I. (60 points) Do all calculations in LATEX + R + knitr. For this assignment, all R code should well commented and be visible (echo=TRUE) in the document where you have written it. Every time ...

Leia mais