FSA icon indicating copy to clipboard operation
FSA copied to clipboard

Multiple groups in psdAdd()

Open droglenc opened this issue 6 months ago • 1 comments

psdAdd() does not properly handle multiple species that have groups. Using these toy data ...

dbt <- data.frame(species=factor(rep(c("Brown Trout"),30)),
                  tl=round(rnorm(30,230,50),0))

dlt <- data.frame(species=factor(rep(c("Chinook Salmon"),30)),
                  tl=round(rnorm(30,550,60),0))

df2 <- rbind(dbt,dlt)

This use of psdAdd() ignores the group for Chinook Salmon (which is not an issue here because there is only one group for Chinook Salmon).

df2$psd <- psdAdd(tl~species,data=df2,
                  group=list("Brown Trout"="lentic","Chinook Salmon"="landlocked"))

However, this use of psdAdd() highlights the problem by throwing a non-sensical (but useful) error for Brown Trout.

df2$psd <- psdAdd(tl~species,data=df2,
                  group=list("Chinook Salmon"="landlocked","Brown Trout"="lentic"))

Thanks to @daveglover for identifying this issue and providing the example code.

droglenc avatar Sep 25 '25 21:09 droglenc