Universidade Federal do Paraná
Curso de Estatística
CE 083 -
Estatística Computacional I - 2014/2
Prof. Dr. Walmes Marques Zeviani
Tabela de conteúdo
##-----------------------------------------------------------------------------
## Criando uma matriz.
X <- matrix(1:6, ncol=2, nrow=5, byrow=TRUE)
## Warning: data length [6] is not a sub-multiple or multiple of the number of rows [5]
## Se o número de elementos para preencher não for múltiplo do número de
## elementos disponíveis na matriz (nrow*ncol), uma mensagem de aviso é
## mostrada.
##-----------------------------------------------------------------------------
## Seleção em matrizes pelo índice.
X[2, 2]
## [1] 4
X[2:3, 2]
## [1] 4 6
X[2:3, 1:2]
## [,1] [,2]
## [1,] 3 4
## [2,] 5 6
X[c(2,5), 1:2]
## [,1] [,2]
## [1,] 3 4
## [2,] 3 4
X[2:3,]
## [,1] [,2]
## [1,] 3 4
## [2,] 5 6
X[,1]
## [1] 1 3 5 1 3
X[-3,]
## [,1] [,2]
## [1,] 1 2
## [2,] 3 4
## [3,] 1 2
## [4,] 3 4
## Se selecionar uma linha ou coluna, o resultado é um vetor (reduz para
## uma dimensão), caso contrário é uma sub-matriz.
##-----------------------------------------------------------------------------
## Atributos do um objeto matriz.
length(X) ## Número de elementos.
## [1] 10
dim(X) ## Dimensões: nrow e ncol.
## [1] 5 2
nrow(X)
## [1] 5
ncol(X)
## [1] 2
str(X) ## Estrutura.
## int [1:5, 1:2] 1 3 5 1 3 2 4 6 2 4
dimnames(X) ## Nome das linhas/colunas caso presente.
## NULL
class(X) ## Classe do objeto.
## [1] "matrix"
typeof(X) ## Tipo de conteúdo.
## [1] "integer"
dput(X) ## Objeto em formato texto pleno.
## structure(c(1L, 3L, 5L, 1L, 3L, 2L, 4L, 6L, 2L, 4L), .Dim = c(5L,
## 2L))
##-----------------------------------------------------------------------------
## Alterando o conteúdo.
X[1,] <- 12:13
X[3,2] <- NA
##-----------------------------------------------------------------------------
## Acrescentar linhas e colunas.
cbind(X, 3*(1:nrow(X))) ## Coluna à direita.
## [,1] [,2] [,3]
## [1,] 12 13 3
## [2,] 3 4 6
## [3,] 5 NA 9
## [4,] 1 2 12
## [5,] 3 4 15
cbind(-3*(1:nrow(X)), X) ## Coluna à esquerda.
## [,1] [,2] [,3]
## [1,] -3 12 13
## [2,] -6 3 4
## [3,] -9 5 NA
## [4,] -12 1 2
## [5,] -15 3 4
rbind(X, c(90, 99)) ## Linha no final.
## [,1] [,2]
## [1,] 12 13
## [2,] 3 4
## [3,] 5 NA
## [4,] 1 2
## [5,] 3 4
## [6,] 90 99
##-----------------------------------------------------------------------------
## Operações com matrizes.
X <- matrix(c(1,3,6,2), 2, 2)
Y <- matrix(c(1,3,6,2,1,8), 3, 2)
K <- matrix(c(6,2,1,8), 2, 2)
## Operações elemento à elemento (elementwise).
X+K
## [,1] [,2]
## [1,] 7 7
## [2,] 5 10
X-K
## [,1] [,2]
## [1,] -5 5
## [2,] 1 -6
X*K
## [,1] [,2]
## [1,] 6 6
## [2,] 6 16
X/K
## [,1] [,2]
## [1,] 0.1667 6.00
## [2,] 1.5000 0.25
## Produto matricial.
X%*%K
## [,1] [,2]
## [1,] 18 49
## [2,] 22 19
X%*%Y
## Error: non-conformable arguments
Y%*%X
## [,1] [,2]
## [1,] 7 10
## [2,] 6 20
## [3,] 30 52
t(X) ## Transpor.
## [,1] [,2]
## [1,] 1 3
## [2,] 6 2
solve(X) ## Inverter.
## [,1] [,2]
## [1,] -0.1250 0.3750
## [2,] 0.1875 -0.0625
det(X) ## Determinante.
## [1] -16
##-----------------------------------------------------------------------------
## Medidas resumo e a diferença dos resultados para diferentes clases de
## objetos.
## Vetor.
x <- round(runif(7*3), 3); x
## [1] 0.144 0.175 0.710 0.650 0.201 0.490 0.777 0.336 0.000 0.481 0.921 0.524 0.693 0.157
## [15] 0.361 0.714 0.743 0.807 0.917 0.405 0.599
X <- matrix(x, 7, 3); X
## [,1] [,2] [,3]
## [1,] 0.144 0.336 0.361
## [2,] 0.175 0.000 0.714
## [3,] 0.710 0.481 0.743
## [4,] 0.650 0.921 0.807
## [5,] 0.201 0.524 0.917
## [6,] 0.490 0.693 0.405
## [7,] 0.777 0.157 0.599
sum(x)
## [1] 10.8
mean(x)
## [1] 0.5145
median(x)
## [1] 0.524
sd(x)
## [1] 0.2722
var(x)
## [1] 0.07409
min(x)
## [1] 0
max(x)
## [1] 0.921
range(x)
## [1] 0.000 0.921
## Enfileira os elementos da matriz para convertê-la em vetor e então
## operar.
sum(X)
## [1] 10.8
mean(X)
## [1] 0.5145
## Retorna matriz de covariância.
var(X)
## [,1] [,2] [,3]
## [1,] 0.074565 0.026060 0.005575
## [2,] 0.026060 0.098078 0.009353
## [3,] 0.005575 0.009353 0.042471
cov(X)
## [,1] [,2] [,3]
## [1,] 0.074565 0.026060 0.005575
## [2,] 0.026060 0.098078 0.009353
## [3,] 0.005575 0.009353 0.042471
cor(X)
## [,1] [,2] [,3]
## [1,] 1.00000 0.3047 0.09907
## [2,] 0.30474 1.0000 0.14492
## [3,] 0.09907 0.1449 1.00000
##-----------------------------------------------------------------------------
## Todos os elementos de vetores e matrizes devem ser do mesmo tipo.
Z <- matrix(runif(3*7), 3)
str(Z)
## num [1:3, 1:7] 0.705 0.456 0.886 0.137 0.933 ...
Z[1,5] <- "a"
str(Z)
## chr [1:3, 1:7] "0.705405356129631" "0.456435702973977" "0.8858148669824" ...
##-----------------------------------------------------------------------------
## Criando uma tabela.
da <- data.frame(nome=c("Lucas", "Paulo", "Ana", "Pedro", "Marcos", "Lúcia"),
idade=c(19, 22, 21, 18, 20, 21),
sexo=c(0,0,1,0,0,1))
str(da)
## 'data.frame': 6 obs. of 3 variables:
## $ nome : Factor w/ 6 levels "Ana","Lucas",..: 2 5 1 6 4 3
## $ idade: num 19 22 21 18 20 21
## $ sexo : num 0 0 1 0 0 1
names(da)
## [1] "nome" "idade" "sexo"
rownames(da)
## [1] "1" "2" "3" "4" "5" "6"
typeof(da)
## [1] "list"
class(da)
## [1] "data.frame"
##-----------------------------------------------------------------------------
## Seleção.
da[1,]
## nome idade sexo
## 1 Lucas 19 0
da[c(1,3),]
## nome idade sexo
## 1 Lucas 19 0
## 3 Ana 21 1
da[-3,]
## nome idade sexo
## 1 Lucas 19 0
## 2 Paulo 22 0
## 4 Pedro 18 0
## 5 Marcos 20 0
## 6 Lúcia 21 1
da[,1]
## [1] Lucas Paulo Ana Pedro Marcos Lúcia
## Levels: Ana Lucas Lúcia Marcos Paulo Pedro
da[,2]
## [1] 19 22 21 18 20 21
da[,c(1:2)]
## nome idade
## 1 Lucas 19
## 2 Paulo 22
## 3 Ana 21
## 4 Pedro 18
## 5 Marcos 20
## 6 Lúcia 21
da[,"idade"]
## [1] 19 22 21 18 20 21
da[,c("sexo","idade")]
## sexo idade
## 1 0 19
## 2 0 22
## 3 1 21
## 4 0 18
## 5 0 20
## 6 1 21
da$idade
## [1] 19 22 21 18 20 21
da$nome
## [1] Lucas Paulo Ana Pedro Marcos Lúcia
## Levels: Ana Lucas Lúcia Marcos Paulo Pedro
##-----------------------------------------------------------------------------
## Algumas tabelas de dados disponíveis no R.
str(cars)
## 'data.frame': 50 obs. of 2 variables:
## $ speed: num 4 4 7 7 8 9 10 10 10 11 ...
## $ dist : num 2 10 4 22 16 10 18 26 34 17 ...
str(mtcars)
## 'data.frame': 32 obs. of 11 variables:
## $ mpg : num 21 21 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 ...
## $ cyl : num 6 6 4 6 8 6 8 4 4 6 ...
## $ disp: num 160 160 108 258 360 ...
## $ hp : num 110 110 93 110 175 105 245 62 95 123 ...
## $ drat: num 3.9 3.9 3.85 3.08 3.15 2.76 3.21 3.69 3.92 3.92 ...
## $ wt : num 2.62 2.88 2.32 3.21 3.44 ...
## $ qsec: num 16.5 17 18.6 19.4 17 ...
## $ vs : num 0 0 1 1 0 1 0 1 1 1 ...
## $ am : num 1 1 1 0 0 0 0 0 0 0 ...
## $ gear: num 4 4 4 3 3 3 3 4 4 4 ...
## $ carb: num 4 4 1 1 2 1 4 2 2 4 ...
str(iris)
## 'data.frame': 150 obs. of 5 variables:
## $ Sepal.Length: num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
## $ Sepal.Width : num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
## $ Petal.Length: num 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
## $ Petal.Width : num 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
## $ Species : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...
str(longley)
## 'data.frame': 16 obs. of 7 variables:
## $ GNP.deflator: num 83 88.5 88.2 89.5 96.2 ...
## $ GNP : num 234 259 258 285 329 ...
## $ Unemployed : num 236 232 368 335 210 ...
## $ Armed.Forces: num 159 146 162 165 310 ...
## $ Population : num 108 109 110 111 112 ...
## $ Year : int 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 ...
## $ Employed : num 60.3 61.1 60.2 61.2 63.2 ...
str(rock)
## 'data.frame': 48 obs. of 4 variables:
## $ area : int 4990 7002 7558 7352 7943 7979 9333 8209 8393 6425 ...
## $ peri : num 2792 3893 3931 3869 3949 ...
## $ shape: num 0.0903 0.1486 0.1833 0.1171 0.1224 ...
## $ perm : num 6.3 6.3 6.3 6.3 17.1 17.1 17.1 17.1 119 119 ...
str(swiss)
## 'data.frame': 47 obs. of 6 variables:
## $ Fertility : num 80.2 83.1 92.5 85.8 76.9 76.1 83.8 92.4 82.4 82.9 ...
## $ Agriculture : num 17 45.1 39.7 36.5 43.5 35.3 70.2 67.8 53.3 45.2 ...
## $ Examination : int 15 6 5 12 17 9 16 14 12 16 ...
## $ Education : int 12 9 5 7 15 7 7 8 7 13 ...
## $ Catholic : num 9.96 84.84 93.4 33.77 5.16 ...
## $ Infant.Mortality: num 22.2 22.2 20.2 20.3 20.6 26.6 23.6 24.9 21 24.4 ...
##-----------------------------------------------------------------------------
## Acrescentando colunas à uma tabela: Proporção de desempregados.
## Dá erro.
Unemployed/(Unemployed+Employed)
## Error: object 'Unemployed' not found
## Usando operador dólar.
longley$Unemployed/(longley$Unemployed+longley$Employed)
## [1] 0.7962 0.7918 0.8595 0.8456 0.7685 0.7522 0.7421 0.8488 0.8148 0.8062 0.8116 0.8756
## [13] 0.8474 0.8496 0.8739 0.8503
## Usando os colchetes.
longley[,"Unemployed"]/(longley[,"Unemployed"]+longley[,"Employed"])
## [1] 0.7962 0.7918 0.8595 0.8456 0.7685 0.7522 0.7421 0.8488 0.8148 0.8062 0.8116 0.8756
## [13] 0.8474 0.8496 0.8739 0.8503
## Usando with().
with(longley, Unemployed/(Unemployed+Employed))
## [1] 0.7962 0.7918 0.8595 0.8456 0.7685 0.7522 0.7421 0.8488 0.8148 0.8062 0.8116 0.8756
## [13] 0.8474 0.8496 0.8739 0.8503
## Criando a nova coluna.
longley$PropoUn <- with(longley, Unemployed/(Unemployed+Employed))
str(longley)
## 'data.frame': 16 obs. of 8 variables:
## $ GNP.deflator: num 83 88.5 88.2 89.5 96.2 ...
## $ GNP : num 234 259 258 285 329 ...
## $ Unemployed : num 236 232 368 335 210 ...
## $ Armed.Forces: num 159 146 162 165 310 ...
## $ Population : num 108 109 110 111 112 ...
## $ Year : int 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 ...
## $ Employed : num 60.3 61.1 60.2 61.2 63.2 ...
## $ PropoUn : num 0.796 0.792 0.86 0.846 0.769 ...
## Removendo essa coluna.
longley <- longley[,-8]
names(longley)
## [1] "GNP.deflator" "GNP" "Unemployed" "Armed.Forces" "Population"
## [6] "Year" "Employed"
##-----------------------------------------------------------------------------
## Filtrar valores por regra lógica.
subset(longley, GNP>250)
## GNP.deflator GNP Unemployed Armed.Forces Population Year Employed
## 1948 88.5 259.4 232.5 145.6 108.6 1948 61.12
## 1949 88.2 258.1 368.2 161.6 109.8 1949 60.17
## 1950 89.5 284.6 335.1 165.0 110.9 1950 61.19
## 1951 96.2 329.0 209.9 309.9 112.1 1951 63.22
## 1952 98.1 347.0 193.2 359.4 113.3 1952 63.64
## 1953 99.0 365.4 187.0 354.7 115.1 1953 64.99
## 1954 100.0 363.1 357.8 335.0 116.2 1954 63.76
## 1955 101.2 397.5 290.4 304.8 117.4 1955 66.02
## 1956 104.6 419.2 282.2 285.7 118.7 1956 67.86
## 1957 108.4 442.8 293.6 279.8 120.4 1957 68.17
## 1958 110.8 444.5 468.1 263.7 122.0 1958 66.51
## 1959 112.6 482.7 381.3 255.2 123.4 1959 68.66
## 1960 114.2 502.6 393.1 251.4 125.4 1960 69.56
## 1961 115.7 518.2 480.6 257.2 127.9 1961 69.33
## 1962 116.9 554.9 400.7 282.7 130.1 1962 70.55
subset(longley, Year>=1955)
## GNP.deflator GNP Unemployed Armed.Forces Population Year Employed
## 1955 101.2 397.5 290.4 304.8 117.4 1955 66.02
## 1956 104.6 419.2 282.2 285.7 118.7 1956 67.86
## 1957 108.4 442.8 293.6 279.8 120.4 1957 68.17
## 1958 110.8 444.5 468.1 263.7 122.0 1958 66.51
## 1959 112.6 482.7 381.3 255.2 123.4 1959 68.66
## 1960 114.2 502.6 393.1 251.4 125.4 1960 69.56
## 1961 115.7 518.2 480.6 257.2 127.9 1961 69.33
## 1962 116.9 554.9 400.7 282.7 130.1 1962 70.55
##-----------------------------------------------------------------------------
## Selecionar colunas.
subset(longley, select=c(Employed, Unemployed))
## Employed Unemployed
## 1947 60.32 235.6
## 1948 61.12 232.5
## 1949 60.17 368.2
## 1950 61.19 335.1
## 1951 63.22 209.9
## 1952 63.64 193.2
## 1953 64.99 187.0
## 1954 63.76 357.8
## 1955 66.02 290.4
## 1956 67.86 282.2
## 1957 68.17 293.6
## 1958 66.51 468.1
## 1959 68.66 381.3
## 1960 69.56 393.1
## 1961 69.33 480.6
## 1962 70.55 400.7
subset(longley, select=-c(GNP, Employed, Unemployed))
## GNP.deflator Armed.Forces Population Year
## 1947 83.0 159.0 107.6 1947
## 1948 88.5 145.6 108.6 1948
## 1949 88.2 161.6 109.8 1949
## 1950 89.5 165.0 110.9 1950
## 1951 96.2 309.9 112.1 1951
## 1952 98.1 359.4 113.3 1952
## 1953 99.0 354.7 115.1 1953
## 1954 100.0 335.0 116.2 1954
## 1955 101.2 304.8 117.4 1955
## 1956 104.6 285.7 118.7 1956
## 1957 108.4 279.8 120.4 1957
## 1958 110.8 263.7 122.0 1958
## 1959 112.6 255.2 123.4 1959
## 1960 114.2 251.4 125.4 1960
## 1961 115.7 257.2 127.9 1961
## 1962 116.9 282.7 130.1 1962
##-----------------------------------------------------------------------------
## Linhas e colunas.
subset(longley, Year>=1955, select=c("Employed", "Unemployed"))
## Employed Unemployed
## 1955 66.02 290.4
## 1956 67.86 282.2
## 1957 68.17 293.6
## 1958 66.51 468.1
## 1959 68.66 381.3
## 1960 69.56 393.1
## 1961 69.33 480.6
## 1962 70.55 400.7
subset(longley, Year>=1955, select=-c(GNP, Employed, Unemployed))
## GNP.deflator Armed.Forces Population Year
## 1955 101.2 304.8 117.4 1955
## 1956 104.6 285.7 118.7 1956
## 1957 108.4 279.8 120.4 1957
## 1958 110.8 263.7 122.0 1958
## 1959 112.6 255.2 123.4 1959
## 1960 114.2 251.4 125.4 1960
## 1961 115.7 257.2 127.9 1961
## 1962 116.9 282.7 130.1 1962
##-----------------------------------------------------------------------------
## Ordenar tabela por valores de uma ou mais colunas.
x <- c(10,100,1,1000)
order(x)
## [1] 3 1 2 4
x[order(x)]
## [1] 1 10 100 1000
sort(x)
## [1] 1 10 100 1000
o <- order(longley$Unem)
longley <- longley[o,]
longley
## GNP.deflator GNP Unemployed Armed.Forces Population Year Employed
## 1953 99.0 365.4 187.0 354.7 115.1 1953 64.99
## 1952 98.1 347.0 193.2 359.4 113.3 1952 63.64
## 1951 96.2 329.0 209.9 309.9 112.1 1951 63.22
## 1948 88.5 259.4 232.5 145.6 108.6 1948 61.12
## 1947 83.0 234.3 235.6 159.0 107.6 1947 60.32
## 1956 104.6 419.2 282.2 285.7 118.7 1956 67.86
## 1955 101.2 397.5 290.4 304.8 117.4 1955 66.02
## 1957 108.4 442.8 293.6 279.8 120.4 1957 68.17
## 1950 89.5 284.6 335.1 165.0 110.9 1950 61.19
## 1954 100.0 363.1 357.8 335.0 116.2 1954 63.76
## 1949 88.2 258.1 368.2 161.6 109.8 1949 60.17
## 1959 112.6 482.7 381.3 255.2 123.4 1959 68.66
## 1960 114.2 502.6 393.1 251.4 125.4 1960 69.56
## 1962 116.9 554.9 400.7 282.7 130.1 1962 70.55
## 1958 110.8 444.5 468.1 263.7 122.0 1958 66.51
## 1961 115.7 518.2 480.6 257.2 127.9 1961 69.33
##-----------------------------------------------------------------------------
## Ordenar por duas variáveis.
str(iris)
## 'data.frame': 150 obs. of 5 variables:
## $ Sepal.Length: num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
## $ Sepal.Width : num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
## $ Petal.Length: num 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
## $ Petal.Width : num 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
## $ Species : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...
head(iris) ## Cabeça.
## Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## 1 5.1 3.5 1.4 0.2 setosa
## 2 4.9 3.0 1.4 0.2 setosa
## 3 4.7 3.2 1.3 0.2 setosa
## 4 4.6 3.1 1.5 0.2 setosa
## 5 5.0 3.6 1.4 0.2 setosa
## 6 5.4 3.9 1.7 0.4 setosa
tail(iris) ## Calda.
## Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## 145 6.7 3.3 5.7 2.5 virginica
## 146 6.7 3.0 5.2 2.3 virginica
## 147 6.3 2.5 5.0 1.9 virginica
## 148 6.5 3.0 5.2 2.0 virginica
## 149 6.2 3.4 5.4 2.3 virginica
## 150 5.9 3.0 5.1 1.8 virginica
## Tem 150 linhas. Evitar de ver na integra.
## iris
o <- with(iris, order(Species, Sepal.Length))
iris <- iris[o,]
head(iris, 15)
## Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## 14 4.3 3.0 1.1 0.1 setosa
## 9 4.4 2.9 1.4 0.2 setosa
## 39 4.4 3.0 1.3 0.2 setosa
## 43 4.4 3.2 1.3 0.2 setosa
## 42 4.5 2.3 1.3 0.3 setosa
## 4 4.6 3.1 1.5 0.2 setosa
## 7 4.6 3.4 1.4 0.3 setosa
## 23 4.6 3.6 1.0 0.2 setosa
## 48 4.6 3.2 1.4 0.2 setosa
## 3 4.7 3.2 1.3 0.2 setosa
## 30 4.7 3.2 1.6 0.2 setosa
## 12 4.8 3.4 1.6 0.2 setosa
## 13 4.8 3.0 1.4 0.1 setosa
## 25 4.8 3.4 1.9 0.2 setosa
## 31 4.8 3.1 1.6 0.2 setosa
##-----------------------------------------------------------------------------
## Procura por uma função ou termo na web.
RSiteSearch("arrange")
##-----------------------------------------------------------------------------
## Instalar. Se faz uma vez apenas.
## Escolha o espelho na janela que abrir.
install.packages("plyr")
## Espelho de preferência informado.
install.packages("doBy", repos="http://cran-r.c3sl.ufpr.br/")
##-----------------------------------------------------------------------------
## Requerir. Se faz em toda sessão (tem como deixar automático).
## Faz requisição.
require(plyr)
## Loading required package: plyr
## Também faz requisição.
library(doBy)
## Loading required package: survival
## Loading required package: splines
## Loading required package: MASS
## Mostra os pacotes carregados.
search()
## [1] ".GlobalEnv" "package:doBy" "package:MASS" "package:survival"
## [5] "package:splines" "package:plyr" "package:knitr" "package:stats"
## [9] "package:graphics" "package:grDevices" "package:utils" "package:datasets"
## [13] "Autoloads" "package:base"
## Mostra as informações da sessão.
sessionInfo()
## R version 3.1.1 (2014-07-10)
## Platform: x86_64-pc-linux-gnu (64-bit)
##
## locale:
## [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=pt_BR.UTF-8
## [4] LC_COLLATE=en_US.UTF-8 LC_MONETARY=pt_BR.UTF-8 LC_MESSAGES=en_US.UTF-8
## [7] LC_PAPER=pt_BR.UTF-8 LC_NAME=C LC_ADDRESS=C
## [10] LC_TELEPHONE=C LC_MEASUREMENT=pt_BR.UTF-8 LC_IDENTIFICATION=C
##
## attached base packages:
## [1] splines stats graphics grDevices utils datasets base
##
## other attached packages:
## [1] doBy_4.5-10 MASS_7.3-34 survival_2.37-7 plyr_1.8.1 knitr_1.6
##
## loaded via a namespace (and not attached):
## [1] evaluate_0.5.5 formatR_0.10 grid_3.1.1 lattice_0.20-29 lme4_1.1-7
## [6] Matrix_1.1-4 methods_3.1.1 minqa_1.2.3 nlme_3.1-117 nloptr_1.0.4
## [11] Rcpp_0.11.2 stringr_0.6.2 tools_3.1.1
## Versão do R.
R.version.string
## [1] "R version 3.1.1 (2014-07-10)"
## Versão do pacote.
packageVersion("doBy")
## [1] '4.5.10'
## Funções/objetos nativos que contém o termo 'version'.
apropos("version")
## [1] "anyNA.numeric_version" "as.character.numeric_version"
## [3] "as.data.frame.numeric_version" "as.list.numeric_version"
## [5] "as.numeric_version" "as.package_version"
## [7] "c.numeric_version" "compareVersion"
## [9] ".decode_numeric_version" "duplicated.numeric_version"
## [11] ".encode_numeric_version" "format.numeric_version"
## [13] "getNamespaceVersion" "getRversion"
## [15] "is.na.numeric_version" "is.numeric_version"
## [17] "is.package_version" "La_version"
## [19] ".make_numeric_version" "[.numeric_version"
## [21] "[[<-.numeric_version" "[[.numeric_version"
## [23] "numeric_version" "Ops.numeric_version"
## [25] "$.package_version" "package_version"
## [27] "packageVersion" "print.numeric_version"
## [29] "rep.numeric_version" "RNGversion"
## [31] "R_system_version" "R.version"
## [33] "R.Version" "R.version.string"
## [35] "Summary.numeric_version" "unique.numeric_version"
## [37] "version" "xtfrm.numeric_version"
## Desacoplar um pacote.
detach("package:doBy")
##-----------------------------------------------------------------------------
## Ordenando o data.frame com funções mais apropriadas.
iris <- arrange(iris, Species, Petal.Length)
head(iris)
## Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## 1 4.6 3.6 1.0 0.2 setosa
## 2 4.3 3.0 1.1 0.1 setosa
## 3 5.0 3.2 1.2 0.2 setosa
## 4 5.8 4.0 1.2 0.2 setosa
## 5 4.4 3.0 1.3 0.2 setosa
## 6 4.4 3.2 1.3 0.2 setosa