data(iris)
iris$Species <- NULL
cor(iris)
## Sepal.Length Sepal.Width Petal.Length Petal.Width
## Sepal.Length 1.0000000 -0.1175698 0.8717538 0.8179411
## Sepal.Width -0.1175698 1.0000000 -0.4284401 -0.3661259
## Petal.Length 0.8717538 -0.4284401 1.0000000 0.9628654
## Petal.Width 0.8179411 -0.3661259 0.9628654 1.0000000
plot(iris$Petal.Length, iris$Sepal.Length, pch=19, col='red')
plot(iris$Sepal.Width, iris$Sepal.Length, pch=19, col='red')
sapply(iris, sd)
## Sepal.Length Sepal.Width Petal.Length Petal.Width
## 0.8280661 0.4358663 1.7652982 0.7622377
hist(iris$Sepal.Width, main="Menor SD encontrado", col='cyan', xlim=c(0,8))
hist(iris$Petal.Length, main="Maior SD encontrado", col='cyan', xlim=c(0,8))
summary(iris)
## Sepal.Length Sepal.Width Petal.Length Petal.Width
## Min. :4.300 Min. :2.000 Min. :1.000 Min. :0.100
## 1st Qu.:5.100 1st Qu.:2.800 1st Qu.:1.600 1st Qu.:0.300
## Median :5.800 Median :3.000 Median :4.350 Median :1.300
## Mean :5.843 Mean :3.057 Mean :3.758 Mean :1.199
## 3rd Qu.:6.400 3rd Qu.:3.300 3rd Qu.:5.100 3rd Qu.:1.800
## Max. :7.900 Max. :4.400 Max. :6.900 Max. :2.500
library(UsingR)
## Loading required package: MASS
## Loading required package: HistData
## Loading required package: Hmisc
## Loading required package: grid
## Loading required package: lattice
## Loading required package: survival
## Loading required package: Formula
## Loading required package: ggplot2
##
## Attaching package: 'Hmisc'
##
## The following objects are masked from 'package:base':
##
## format.pval, round.POSIXt, trunc.POSIXt, units
##
##
## Attaching package: 'UsingR'
##
## The following object is masked from 'package:ggplot2':
##
## movies
##
## The following object is masked from 'package:survival':
##
## cancer
data(survey)
names(survey)
## [1] "Sex" "Wr.Hnd" "NW.Hnd" "W.Hnd" "Fold" "Pulse" "Clap"
## [8] "Exer" "Smoke" "Height" "M.I" "Age"
Age: idade em anos do estudante.
Existem valores NA no dataset? Quantos?
sum(is.na(survey))
## [1] 107
prop.table(table(survey$W.Hnd))
##
## Left Right
## 0.07627119 0.92372881
table(survey$Sex)
##
## Female Male
## 118 118
library(ggplot2)
qplot(survey$Wr.Hnd, survey$NW.Hnd, col=survey$Sex, size=survey$Height)
## Warning: Removed 29 rows containing missing values (geom_point).
qplot(survey$Wr.Hnd, survey$NW.Hnd, col=survey$W.Hnd, size=survey$Pulse)
## Warning: Removed 46 rows containing missing values (geom_point).
abalos <- read.csv("http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_month.csv")
Entenda melhor o significado de cada atributo acessando o site http://earthquake.usgs.gov/earthquakes/feed/v1.0/csv.php.
Armazene o dia e horário quando os dados foram coletados.
diaHorario <- date()
dim(abalos)
## [1] 8582 22
sapply(abalos, class)
## time latitude longitude depth
## "factor" "numeric" "numeric" "numeric"
## mag magType nst gap
## "numeric" "factor" "integer" "numeric"
## dmin rms net id
## "numeric" "numeric" "factor" "factor"
## updated place type horizontalError
## "factor" "factor" "factor" "numeric"
## depthError magError magNst status
## "numeric" "numeric" "integer" "factor"
## locationSource magSource
## "factor" "factor"
O R conseguiu importar corretamente todos os atributos com os tipos corretos?
Quantos tipos distintos de abalos existem no dataset?
levels(abalos$type)
## [1] "chemical explosion" "earthquake" "explosion"
## [4] "other event" "quarry blast"
cor(abalos$depth, abalos$mag)
## [1] NA
plot(abalos$depth, abalos$mag, pch=19, col="green")
qplot(abalos$depth, abalos$mag, col=abalos$type,
xlab="Profundidade", ylab="Magnitude")
## Warning: Removed 31 rows containing missing values (geom_point).
boxplot(abalos$mag ~ abalos$type,
col=c('red','blue','cyan','green'),
main="Comparativo de magnitude",
ylab="Magnitude")
datas <- as.Date(abalos$time, "%Y-%m-%dT%H:%M:%S")
eventos <- as.data.frame(table(datas))
names(eventos) <- c('data','quantidade')
eventos$data <- as.Date(eventos$data, "%Y-%m-%d")
plot(eventos$data, eventos$quantidade, type='o', xlab="PerÃodo", ylab="Quantidade de abalos"
, main="Quantidade de abalos sÃsmicos por dia", col='red')
library(maps)
##
## # ATTENTION: maps v3.0 has an updated 'world' map. #
## # Many country borders and names have changed since 1990. #
## # Type '?world' or 'news(package="maps")'. See README_v3. #
library(mapdata)
map(mar = c(0.1, 0.1, 0.1, 0.1), myborder=0.00001)
points(abalos$longitude, abalos$latitude, col=2, pch=20)
library(maps)
library(mapdata)
map(mar = c(0.1, 0.1, 0.1, 0.1), myborder=0.00001)
points(abalos$longitude, abalos$latitude, col=abalos$type, pch=20)
legend("topright",
legend = levels(abalos$type),
text.col = 1:length(abalos$type),
cex=0.6)
library(maps)
library(mapdata)
map(mar = c(0.1, 0.1, 0.1, 0.1), myborder=0.00001)
points(abalos$longitude, abalos$latitude, col=abalos$magType, pch=20)
legend("topright",
legend = levels(abalos$magType),
text.col = 1:length(abalos$magType),
cex=0.6)