Skip to content

Instantly share code, notes, and snippets.

@symbolrush
Created April 13, 2016 06:01
Show Gist options
  • Save symbolrush/2510d32d8d3acd3d5592227bc23bb7f4 to your computer and use it in GitHub Desktop.
Save symbolrush/2510d32d8d3acd3d5592227bc23bb7f4 to your computer and use it in GitHub Desktop.
subsetting (filtering) of df's
# Testdaten
df <- data.frame(category = c(1,2,3,1,3,2,1), value = rep(10, 7))
# Variante 1:
# Die Klassiker
df[df$category == 2,]
subset(df, category == 2)
# Variante 2:
# mit dem dplyr package. Unterschied: die Zeilen bekommen neue fortlaufende Nummern
# das kann Vorteile bieten..
filter(df, category == 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment