Created
November 21, 2014 11:51
-
-
Save mhermans/8407cbcf3dd3b67b64c5 to your computer and use it in GitHub Desktop.
Berkeken groepsgemiddelden in R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Berkeken groepsgemiddelden in R | |
data(iris) | |
summary(iris) | |
str(iris) | |
typeof(iris$Petal.Length) | |
typeof(iris$Species) | |
class(iris$Petal.Length) | |
class(iris$Species) | |
# Ingebouwd: aggregate() | |
aggregate(Sepal.Length~Species, iris, mean) | |
# Ingebouwd: tapply() | |
tapply(iris$Sepal.Length, iris$Species, mean) | |
# Ingebouwd: ave() | |
ave(iris$Sepal.Length, iris$Species) # geeft een vector terug met gemiddeld per group voor elke obsv. | |
# via library plyr | |
library(plyr) | |
# geeft datatable terug met verschillende variabelen per aggregerende functie | |
ddply(iris,~Species, summarise, | |
min=min(Sepal.Length), | |
max=max(Sepal.Length), | |
mean=mean(Sepal.Length), | |
sd=sd(Sepal.Length)) | |
# geeft dataset terug met nieuwe var "groep_gem" met gem. groepswaarde per obsv | |
ddply(iris, "Species", transform, groep_gem = mean(Sepal.Length)) | |
# via library doBy | |
library(doBy) | |
summaryBy(Sepal.Length ~ Species, data=iris, FUN=mean) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment