Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#### Download HQ male song recordings > 30s long from Europe ####
query <- querxc("type:song type:male len_gt:30 q_gt:C area:europe")
query$Species <- with(query, paste(Genus, Specific_epithet))
# Select top 50 most abundant bird species
speciesCount <- sort(table(query$Species), decreasing = T)
topSpecies <- names(speciesCount)[1:50]
query <- query[query$Species %in% topSpecies, ]
# Downsample to min size among the 50 classes
balancedClasses <- lapply(topSpecies, function(x){
set.seed(100)
sample(which(query$Species == x), min(table(query$Species)))
}) %>% unlist()
# Subset accordingly
query <- query[balancedClasses, ]
# Download using updated query
querxc(X = query, download = T, path = "mp3/", parallel = 8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.