Last active
December 2, 2015 17:10
-
-
Save cboettig/7ce0f311daa428b023f9 to your computer and use it in GitHub Desktop.
dplyr group_by() example
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
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) |
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
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