Skip to content

Instantly share code, notes, and snippets.

@Su-Shee
Created January 22, 2013 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Su-Shee/4595381 to your computer and use it in GitHub Desktop.
Save Su-Shee/4595381 to your computer and use it in GitHub Desktop.
example R code
# And what's the largest number of men and women in any neighbourhood?
max(aggregate(csv$Anzahl, by = list(csv$Bezirk), FUN = sum)[[2]])
# That doesn't really help, does it? So, display more information - in
# which row do we have the highest number?
which.max(aggregate(csv$Anzahl, by = list(csv$Bezirk), FUN = sum)[[2]])
# Still no use - let's display the entire row:
allHoods <- aggregate(csv$Anzahl, by = list(csv$Bezirk), FUN = sum)
maxRow <- which.max(allHoods[[2]])
allHoods[maxRow,]
# In which neighbourhood live the most women?
femaleMax <- which.max(allHoods[ grep("f", allHoods$Group.2), ][[3]])
allHoods[femaleMax,]
# And some basic descriptive statistics for the women in Berlin:
summary(allHoods[ grep("f", allHoods$Group.2), ][[3]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment