Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
susyelo opened this issue Sep 28, 2018 · 0 comments
Open

Comments

@susyelo
Copy link
Member

susyelo commented Sep 28, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant