Last active
March 1, 2017 07:37
-
-
Save valentinitnelav/194afb16cd5223b7f98e87b129db04e7 to your computer and use it in GitHub Desktop.
count species by lake combinations
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
# ================================ | |
# 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