Skip to content

Instantly share code, notes, and snippets.

@cboettig
Last active December 2, 2015 17:10
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 cboettig/7ce0f311daa428b023f9 to your computer and use it in GitHub Desktop.
Save cboettig/7ce0f311daa428b023f9 to your computer and use it in GitHub Desktop.
dplyr group_by() example
import datascience as ds
values = temp = ds.Table.read_table("https://raw.githubusercontent.com/boettiger-lab/espm-88b/master/modules/fish/data/RAM-Legacy-DB/values.csv")
def collapsed(an_array):
return an_array[-1] < 0.1*max(an_array)
values.select(['assessid', 'ssb']).group('assessid', collapsed)
library("dplyr")
values <- read.csv("https://raw.githubusercontent.com/boettiger-lab/espm-88b/master/modules/fish/data/RAM-Legacy-DB/values.csv")
collapsed <- function(x)
x[length(x)] < 0.1 * max(x, na.rm=TRUE)
values %>% group_by(assessid) %>% summarise(collapsed(ssb))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment