this question has answer here:
a surveyor submits of bird species captured during season. want subset out captures each species own dataframe. can write out individual species, such i’ve done in last line below. i’d slicker that, , not have go through entire 300 possible species. options?
birds <-c() birds$species <-c("revi","scta","revi","kiwa","baor","mawa","mawa","baor") birds <- as.data.frame(birds) sp <- unique(birds$species) revi <- subset(birds,species=="revi")
thanks.
as @richard scriven points out, can rather using split
. should work:
res<-split(birds,birds$species)
we tell r split birds dataframe species
variable. can access specific species level data.frames
doing call such as:
res[["baor"]] species 5 baor 8 baor
we can see result in fact data.frame
by:
class(res[["baor"]]) [1] "data.frame"