Skip to content

If else statements in this case do not apply for vectorized replacement #2

@susyelo

Description

@susyelo

https://github.com/KerkhoffLab/climate-velocity/blob/0db4745cbd3f974558ae769a6b5588c6b3616dfe/functions/bioclim.var.r#L80

Notice that these if-else statements are only using the first value of the qrt.prc$colMax and calculating the variable using only the information for the quarter where only the first value of qrt.prc$colMax is equal to the statement. In this case, the first value of colMax is equal to "aso" which means that the bio8 variables for ALL the sites are the average value of aug, sep, oct.

In this case, I consider the best syntax to be:

ix <- which(qrt.prc$colMax=="jfm")
clim$bio8[ix] <- ((temp$jan + temp$feb + temp$mar)/3)[ix]

In this case, each site will have different values of Bio8 depending on the colMax value. Before, only the "aso" site were having correct values.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions