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

period.apply inconsistent behaviour with mean and median functions #128

Closed
wrobell opened this issue Dec 2, 2015 · 2 comments
Closed

period.apply inconsistent behaviour with mean and median functions #128

wrobell opened this issue Dec 2, 2015 · 2 comments
Milestone

Comments

@wrobell
Copy link

wrobell commented Dec 2, 2015

The issue below is for xts 0.9.

Please consider the following example

library(xts)

data = data.frame(a=1:5, b=11:15, ts=as.POSIXct(1:5, origin='2015-10-10'))
data = xts(data[,c('a', 'b')], order.by=data$ts)

ends = endpoints(data, 'seconds', 2)

Taking mean of values every 2s gives data frame with a and b columns

> period.apply(data, ends, mean)
                      a    b
2015-10-10 01:00:01 1.0 11.0
2015-10-10 01:00:03 2.5 12.5
2015-10-10 01:00:05 4.5 14.5

I would expect period.apply to behave in similar way for median function, but

> period.apply(data, ends, median)
                    [,1]
2015-10-10 01:00:01  6.0
2015-10-10 01:00:03  7.5
2015-10-10 01:00:05  9.5

Also

> period.apply(data, ends, function(x) mean(x))
                    [,1]
2015-10-10 01:00:01  6.0
2015-10-10 01:00:03  7.5
2015-10-10 01:00:05  9.5

but according to the documentation above should be the same as period.apply(data, ends, mean).

@joshuaulrich
Copy link
Owner

Thanks for the reproducible example. This is related to #124. If mean.xts is either removed or renamed to mean_xts, then period.apply(data, ends, mean) returns a 1-column object consistent with your other examples.

It is interesting that period.apply(data, ends, mean) and period.apply(data, ends, function(x) mean(x)) don't return the same results. Given the direction decided in #124, I'm not going to investigate this curiosity further.

@joshuaulrich
Copy link
Owner

Closing as duplicate of #124.

@joshuaulrich joshuaulrich added this to the 0.13.2 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants