Derek Corcoran
"06/03, 2018"
Paquete con pocas funciones muy poderosas, trabajaremos con
library(dplyr)
library(knitr)
MEAN <- summarize(iris, MEAN.PETAL = mean(Petal.Length))
kable(MEAN)
MEAN.PETAL |
---|
3.758 |
library(dplyr)
library(knitr)
MEAN <- group_by(iris, Species)
MEAN <- summarize(MEAN, MEAN.PETAL = mean(Petal.Length))
kable(MEAN)
Species | MEAN.PETAL |
---|---|
setosa | 1.462 |
versicolor | 4.260 |
virginica | 5.552 |
library(dplyr)
library(knitr)
MEAN <- iris %>% group_by(Species) %>% summarize(MEAN.PETAL = mean(Petal.Length))
kable(MEAN)
Species | MEAN.PETAL |
---|---|
setosa | 1.462 |
versicolor | 4.260 |
virginica | 5.552 |
library(dplyr)
library(knitr)
MEAN <- iris %>% group_by(Species) %>% summarize_all(mean)
kable(MEAN)
Species | Sepal.Length | Sepal.Width | Petal.Length | Petal.Width |
---|---|---|---|---|
setosa | 5.006 | 3.428 | 1.462 | 0.246 |
versicolor | 5.936 | 2.770 | 4.260 | 1.326 |
virginica | 6.588 | 2.974 | 5.552 | 2.026 |
simbolo | significado | simbolo_cont | significado_cont |
---|---|---|---|
< | Menor que | != | distinto a |
> | Mayor que | %in% | dentro del grupo |
== | Igual a | is.na | es NA |
>= | mayor o igual a | !is.na | no es NA |
<= | menor o igual a | | & | o, y |
library(dplyr)
data("iris")
DF <- iris %>% filter(Species != "versicolor") %>% group_by(Species) %>% summarise_all(funs(mean, sd))
kable(DF)
Species | Sepal.Length_mean | Sepal.Width_mean | Petal.Length_mean | Petal.Width_mean | Sepal.Length_sd | Sepal.Width_sd | Petal.Length_sd | Petal.Width_sd |
---|---|---|---|---|---|---|---|---|
setosa | 5.006 | 3.428 | 1.462 | 0.246 | 0.3524897 | 0.3790644 | 0.1736640 | 0.1053856 |
virginica | 6.588 | 2.974 | 5.552 | 2.026 | 0.6358796 | 0.3224966 | 0.5518947 | 0.2746501 |
library(dplyr)
library(knitr)
data(nasa)
Nasa2 <- as.data.frame(nasa)
Temp <- Nasa2 %>% filter(year != 1995) %>% group_by(year) %>% select(contains("temp")) %>% summarize_all(mean)
kable(Temp)
year | surftemp | temperature |
---|---|---|
1996 | 295.8562 | 297.1005 |
1997 | 296.7291 | 297.9566 |
1998 | 297.1221 | 298.7028 |
1999 | 295.6850 | 298.1364 |
2000 | 295.7263 | 298.3358 |
library(ggplot2)
data("diamonds")
ggplot(diamonds, aes(x = carat, y=price)) + geom_point(aes(color = cut)) + theme_classic()
library(ggplot2)
data("diamonds")
ggplot(diamonds, aes(x = carat, y=price)) + geom_point(aes(color = cut)) + theme_classic()
library(ggplot2)
data("diamonds")
ggplot(diamonds, aes(x = carat, y=price)) + geom_point(aes(color = cut), alpha = 0.1) + theme_classic()
library(ggplot2)
data("mtcars")
ggplot(mtcars, aes(x = wt, y=mpg)) + geom_point(aes(size = hp)) + theme_classic()
library(ggplot2)
data("diamonds")
ggplot(diamonds, aes(x = carat, y=price)) + geom_point(aes(shape = cut)) + theme_classic()
library(dplyr)
d2 <- diamonds %>% filter(clarity == "I1" | clarity == "IF")
ggplot(d2, aes(x = cut, y=price)) + geom_boxplot(aes(fill = clarity)) + theme_classic()
data("iris")
ggplot(iris, aes(x = Species, y = Petal.Length)) + geom_jitter(aes(color = Species))
data("iris")
ggplot(iris, aes(x = Species, y = Petal.Length)) + geom_violin(fill = "red")
data("iris")
ggplot(iris, aes(x = Species, y = Petal.Length)) + geom_violin() + geom_jitter(aes(color = Species))
data("iris")
ggplot(iris, aes(x = Species, y = Petal.Length)) + geom_jitter(aes(color = Species)) + geom_violin()