Skip to content

Instantly share code, notes, and snippets.

@valentinitnelav
Last active March 1, 2017 07:37
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 valentinitnelav/194afb16cd5223b7f98e87b129db04e7 to your computer and use it in GitHub Desktop.
Save valentinitnelav/194afb16cd5223b7f98e87b129db04e7 to your computer and use it in GitHub Desktop.
count species by lake combinations
# ================================
# helper script for species counts (lakes for Leana)
# ================================
library(data.table)
# read data
lake_data <- fread("links_extract_dt.csv")
# count unique species by combination of `Pond Name`, Town, County
# skip or add column in the "by" section if needed
lake_data[, Species_Num := uniqueN(Names), by = .(`Pond Name`, Town, County)]
# if "Caughts" is zero, then should be no species, so Species_Num = 0 in that case
lake_data[, Species_Num := ifelse(Caughts == 0, yes = 0, no = Species_Num)]
# save results to csv file
write.csv(lake_data, "lake_data.csv", row.names = FALSE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment