Skip to content

Incorrect month order in zApply function

2 messages · Oscar Perpiñan, Thiago V. dos Santos

#
Hello,

With the current code of zApply, you should use a function that returns an ordered vector. For example:

Month <- function(x)
{
    idx <- as.numeric(format(x, '%m'))
    factor(month.name[idx],
           levels = month.name,
           ordered = TRUE)
}


x2 <- zApply(s, by = Month, mean)

Best,

Oscar.
#
Thanks for the information, Oscar. Perhaps it would be a good idea to include it in the zApply description within the raster manual??
Best,?Thiago.?

Sent from Yahoo Mail on Android 
 
  On Thu, Aug 4, 2016 at 3:19 AM, Oscar Perpi??n Lamigueiro<oscar.perpinan at upm.es> wrote:   Hello,

With the current code of zApply, you should use a function that returns an ordered vector. For example:

Month <- function(x)
{
? ? idx <- as.numeric(format(x, '%m'))
? ? factor(month.name[idx],
? ? ? ? ? levels = month.name,
? ? ? ? ? ordered = TRUE)
}


x2 <- zApply(s, by = Month, mean)

Best,

Oscar.