Download - Beabá do R
![Page 1: Beabá do R](https://reader033.vdocuments.pub/reader033/viewer/2022060203/559e96a41a28ab12128b45c8/html5/thumbnails/1.jpg)
Aa Bb Cc Dd Ee Ff Gg Hh Ii Jj Kk Ll Mm Nn Oo Pp Qq Rr Ss Tt Uu Vv Ww Xx Yy Zz
Beabá do
16 de janeiro de 2013Rodrigo Rocha Gomes e Souza ([email protected])CPDx. Centro de Processamento de Dados (CPD), Universidade Federal da Bahia (UFBA) https://blog.ufba.br/cpdx
![Page 2: Beabá do R](https://reader033.vdocuments.pub/reader033/viewer/2022060203/559e96a41a28ab12128b45c8/html5/thumbnails/2.jpg)
![Page 3: Beabá do R](https://reader033.vdocuments.pub/reader033/viewer/2022060203/559e96a41a28ab12128b45c8/html5/thumbnails/3.jpg)
![Page 4: Beabá do R](https://reader033.vdocuments.pub/reader033/viewer/2022060203/559e96a41a28ab12128b45c8/html5/thumbnails/4.jpg)
![Page 5: Beabá do R](https://reader033.vdocuments.pub/reader033/viewer/2022060203/559e96a41a28ab12128b45c8/html5/thumbnails/5.jpg)
![Page 6: Beabá do R](https://reader033.vdocuments.pub/reader033/viewer/2022060203/559e96a41a28ab12128b45c8/html5/thumbnails/6.jpg)
![Page 7: Beabá do R](https://reader033.vdocuments.pub/reader033/viewer/2022060203/559e96a41a28ab12128b45c8/html5/thumbnails/7.jpg)
estatísticamineração de dadosvisualização de dados
...
![Page 8: Beabá do R](https://reader033.vdocuments.pub/reader033/viewer/2022060203/559e96a41a28ab12128b45c8/html5/thumbnails/8.jpg)
![Page 9: Beabá do R](https://reader033.vdocuments.pub/reader033/viewer/2022060203/559e96a41a28ab12128b45c8/html5/thumbnails/9.jpg)
software liv e
![Page 10: Beabá do R](https://reader033.vdocuments.pub/reader033/viewer/2022060203/559e96a41a28ab12128b45c8/html5/thumbnails/10.jpg)
multiplatafo ma
![Page 11: Beabá do R](https://reader033.vdocuments.pub/reader033/viewer/2022060203/559e96a41a28ab12128b45c8/html5/thumbnails/11.jpg)
ápida!
![Page 12: Beabá do R](https://reader033.vdocuments.pub/reader033/viewer/2022060203/559e96a41a28ab12128b45c8/html5/thumbnails/12.jpg)
dive sospacotes
![Page 13: Beabá do R](https://reader033.vdocuments.pub/reader033/viewer/2022060203/559e96a41a28ab12128b45c8/html5/thumbnails/13.jpg)
muito mate ial
![Page 14: Beabá do R](https://reader033.vdocuments.pub/reader033/viewer/2022060203/559e96a41a28ab12128b45c8/html5/thumbnails/14.jpg)
fácil de integ ara outras linguagens
![Page 15: Beabá do R](https://reader033.vdocuments.pub/reader033/viewer/2022060203/559e96a41a28ab12128b45c8/html5/thumbnails/15.jpg)
lê vá iasfontes de dados
![Page 16: Beabá do R](https://reader033.vdocuments.pub/reader033/viewer/2022060203/559e96a41a28ab12128b45c8/html5/thumbnails/16.jpg)
elatóriosem PDF (com LaTeX)
![Page 17: Beabá do R](https://reader033.vdocuments.pub/reader033/viewer/2022060203/559e96a41a28ab12128b45c8/html5/thumbnails/17.jpg)
é uma linguagemde prog amação
![Page 18: Beabá do R](https://reader033.vdocuments.pub/reader033/viewer/2022060203/559e96a41a28ab12128b45c8/html5/thumbnails/18.jpg)
você p ecisasaber estatística
![Page 19: Beabá do R](https://reader033.vdocuments.pub/reader033/viewer/2022060203/559e96a41a28ab12128b45c8/html5/thumbnails/19.jpg)
bom parag áficos estáticos
![Page 20: Beabá do R](https://reader033.vdocuments.pub/reader033/viewer/2022060203/559e96a41a28ab12128b45c8/html5/thumbnails/20.jpg)
dados namemó ia
![Page 21: Beabá do R](https://reader033.vdocuments.pub/reader033/viewer/2022060203/559e96a41a28ab12128b45c8/html5/thumbnails/21.jpg)
mão na massa
![Page 22: Beabá do R](https://reader033.vdocuments.pub/reader033/viewer/2022060203/559e96a41a28ab12128b45c8/html5/thumbnails/22.jpg)
![Page 23: Beabá do R](https://reader033.vdocuments.pub/reader033/viewer/2022060203/559e96a41a28ab12128b45c8/html5/thumbnails/23.jpg)
![Page 24: Beabá do R](https://reader033.vdocuments.pub/reader033/viewer/2022060203/559e96a41a28ab12128b45c8/html5/thumbnails/24.jpg)
Sumário
‣Tipos de dados: vetor, data frame
‣Manipulação de dados
‣Criação de gráficos
‣Testes de hipótese
![Page 25: Beabá do R](https://reader033.vdocuments.pub/reader033/viewer/2022060203/559e96a41a28ab12128b45c8/html5/thumbnails/25.jpg)
Construção de vetor: c()
‣c(1, 2, 3, 4)
‣1:4 (igual ao anterior)
‣5 (vetor de um elemento)
‣c(“a”, “b”, “c”, “a”)
‣c(T, F, T, T)
![Page 26: Beabá do R](https://reader033.vdocuments.pub/reader033/viewer/2022060203/559e96a41a28ab12128b45c8/html5/thumbnails/26.jpg)
Atribuição: <-
‣nome <- “Fulano”
‣temperaturas.maximas <- c(27, 31, 28)
‣(ponto faz parte do nome da variável)
‣x <- 1:10
![Page 27: Beabá do R](https://reader033.vdocuments.pub/reader033/viewer/2022060203/559e96a41a28ab12128b45c8/html5/thumbnails/27.jpg)
Atribuição e Indexação
‣x <- c(“a”, “b”, “c”, “d”, “e”)
‣x[1] # “a”
‣x[c(1, 3)] # “a” “c”
‣x[c(T, F, T, F, F)] # “a” “c”
![Page 28: Beabá do R](https://reader033.vdocuments.pub/reader033/viewer/2022060203/559e96a41a28ab12128b45c8/html5/thumbnails/28.jpg)
Modificação do vetor‣x[1] <- “A”
‣“A” “b” “c” “d” “e”
‣x[1:3] <- “Z”
‣“Z” “Z” “Z” “d” “e”
‣x[c(F, F, F, F, T)] <- “U”
‣“Z” “Z” “Z” “d” “U”
![Page 29: Beabá do R](https://reader033.vdocuments.pub/reader033/viewer/2022060203/559e96a41a28ab12128b45c8/html5/thumbnails/29.jpg)
Funções
‣notas <- c(9, 8, 9, 10, 7, 5, 7, 8)
‣length(notas) # 8
‣sum(notas) # 63
‣mean(notas) # 7.875 (média)
‣sd(notas) # 1.552648 (desvio-padrão)
![Page 30: Beabá do R](https://reader033.vdocuments.pub/reader033/viewer/2022060203/559e96a41a28ab12128b45c8/html5/thumbnails/30.jpg)
NA: valor faltando
‣notas[10] <- 9
‣9 8 9 10 7 5 7 8 NA 9
‣mean(notas)
‣NA
‣mean(notas, na.rm=T)
‣8
![Page 31: Beabá do R](https://reader033.vdocuments.pub/reader033/viewer/2022060203/559e96a41a28ab12128b45c8/html5/thumbnails/31.jpg)
Operações vetorizadas
‣notas <- c(9, 8, 9, 10, 7, 5, 7, 8, 9, 9)
‣notas * 2
‣18 16 18 20 14 10 14 16 18 18
‣notas == 9
‣T F T F F F F F T T
![Page 32: Beabá do R](https://reader033.vdocuments.pub/reader033/viewer/2022060203/559e96a41a28ab12128b45c8/html5/thumbnails/32.jpg)
Filtro
‣notas > 7 & notas < 10
‣T T T F F F F T T T
‣notas %in% c(8, 9)
‣T T T F F F F T T T
![Page 33: Beabá do R](https://reader033.vdocuments.pub/reader033/viewer/2022060203/559e96a41a28ab12128b45c8/html5/thumbnails/33.jpg)
Filtro‣notas[c(T, T, T, F, F, F, F, T, T, T)]
‣9 8 9 8 9 9
‣notas[notas > 7 & notas < 10]
‣9 8 9 8 9 9
‣notas[notas %in% c(8, 9)]
‣9 8 9 8 9 9
![Page 34: Beabá do R](https://reader033.vdocuments.pub/reader033/viewer/2022060203/559e96a41a28ab12128b45c8/html5/thumbnails/34.jpg)
Outras coisas
‣ifelse(notas >= 7, “A”, “R”)
‣"A" "A" "A" "A" "R" "R" "R" "A" "A" "A"
‣table(notas)
‣ 5 7 8 9 10 1 2 2 4 1
![Page 35: Beabá do R](https://reader033.vdocuments.pub/reader033/viewer/2022060203/559e96a41a28ab12128b45c8/html5/thumbnails/35.jpg)
Gráficos
‣hist
‣plot
‣boxplot
‣pie
‣mosaicplot
![Page 36: Beabá do R](https://reader033.vdocuments.pub/reader033/viewer/2022060203/559e96a41a28ab12128b45c8/html5/thumbnails/36.jpg)
Data frame
nome idade alturaFulano 19 1.70
Beltrano 32 1.67Sicrano 47 1.92
John 82 1.61Paul 64 1.57
George 25 1.77Ringo 76 1.68
vetor vetor vetor
![Page 37: Beabá do R](https://reader033.vdocuments.pub/reader033/viewer/2022060203/559e96a41a28ab12128b45c8/html5/thumbnails/37.jpg)
Carregando data frame
‣x <- read.table(“arquivo”, sep=“\t”, header=T)
‣x <- read.csv(“arquivo”)
![Page 38: Beabá do R](https://reader033.vdocuments.pub/reader033/viewer/2022060203/559e96a41a28ab12128b45c8/html5/thumbnails/38.jpg)
Indexação‣x$nome # retorna coluna nome (um vetor)
‣x[ linhas, colunas ]
‣x[1, ] # data frame com primeira linha
‣x[ , 1] # primeira coluna (vetor)
‣x[ , “nome”] # coluna nome
‣x[1:3, c(“nome”, “altura”)]
![Page 39: Beabá do R](https://reader033.vdocuments.pub/reader033/viewer/2022060203/559e96a41a28ab12128b45c8/html5/thumbnails/39.jpg)
Filtros
‣x[x$idade > 40, ]
‣subset(x, idade > 40)
‣head(x) # retorna primeiras 6 linhas
‣tail(x) # retorna últimas 6 linhas
![Page 40: Beabá do R](https://reader033.vdocuments.pub/reader033/viewer/2022060203/559e96a41a28ab12128b45c8/html5/thumbnails/40.jpg)
Misc
‣x$idade <- 2013 - x$ano.nascimento # nova coluna
‣x$idade <- NULL # remover coluna
‣summary(x) # sumário estatístico
‣nrow(x) # número de linhas
![Page 41: Beabá do R](https://reader033.vdocuments.pub/reader033/viewer/2022060203/559e96a41a28ab12128b45c8/html5/thumbnails/41.jpg)
Para saber mais
The Art of R Programming
R in Action
http://www.statmethods.net/
http://tryr.codeschool.com/
http://www.r-project.org/