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

Please document: xts( , order.by ) order.by' cannot contain 'NA', 'NaN', or 'Inf' #199

Closed
AndreMikulec opened this issue Jul 15, 2017 · 6 comments

Comments

@AndreMikulec
Copy link

In

xts_0.10-0 ( # > xts_0.9-7 )

The following was added sometime.

> debug(xts)

debug: if (any(!is.finite(index))) stop("'order.by' cannot contain 'NA', 'NaN', or 'Inf'")
Browse[2]> index
[1]         NA         NA 1196208000         NA         NA         NA

That makes sense.
Please add documentation to 'xts', 'as.xts', and 'xtsible'.

order.by' cannot contain 'NA', 'NaN', or 'Inf'

I became suprised when my xtsible returned FALSE instead of TRUE.

Thanks,
Andre

@joshuaulrich
Copy link
Owner

Thanks for the report! It was added in commit c24c682. I'll update the documentation to explain the rationale for the change.

@sinyi-chou
Copy link

sinyi-chou commented Jul 18, 2017

I also bumped into this problem but cannot find any description in the latest version of documentation,either. Please help to add the documentation.

Moreover, I have some questions regarding to this issue. The question is the results after aggregating are different from the results by previous version. First, I have a dataset (2 columns, one is the time stamp and another is some kind of measurement for each time stamp) which contains some NA both for time stamp and values. Next, I transform the dataset into xts format in order to obtain the mean value for each week. In the previous version, it works well without the warning. After installing the latest version, the script cannot work anymore

because of the warning order.by' cannot contain 'NA', 'NaN', or 'Inf'

Therefore, I tried na.omit() to exclude the NA values in my dataset. The codes works now but the mean values for each week are different from the ones I got by the previous version. So how does the rules change in the latest version so that the result of aggregation changes? I really want to know the reasons why they are different and which average is correct. Thank you so much.

@braverock
Copy link
Contributor

NA index values are no longer 'allowed' because, by definition, if the time series is indexed by a timestamp, you must know the index value to place the observation correctly in relation to other observations.

So, @CSYMMC I don't understand how you could have a missing timestamp.

Given your description, it sounds as though you have two time series, with different mostly overlapping indices, which should be merged via merge() or cbind() after conversion to xts.

@joshuaulrich
Copy link
Owner

Here's my attempt to document the rationale for the change. Feedback welcome!

As of version 0.10-0, xts no longer allows missing values in the index. This is because many xts functions expect all index values to be finite. The most important of these is merge.xts, which is used ubiquitously. Missing values in the index are usually the result of a date-time conversion error (e.g. incorrect format, non-existent time due to daylight saving time, etc). Because of how non-finite numbers are represented, a missing timestamp will always be at the end of the index (except if it is -Inf, which will be first).

@crazygarnett
Copy link

Dear All,

I am relatively new to R programming and wonder if you could help me to address an error issue.
Specifically, I am struggling to create a datetime index for the data frame.

Here is the code:


# Read XAU prices data file
xau_df <- read_csv(".../XAU_USD.csv")

# Reformat date column as Date type Month/Date/Year
xau_df$date <- as.Date(xau_df$date, format = "%m/%d/%y")

# Create a Datetime index for the DataFrame

xau_xts = xts(select(xau_df,-c("date")),
             order.by = as.POSIXct(strptime(xau_df$date,"%Y-%m-%d"))) 

## error message

Error in xts(select(xau_df, -c("date")), order.by = as.POSIXct(strptime(xau_df$date, : 'order.by' cannot contain 'NA', 'NaN', or 'Inf'


Would you please let me know what is wrong and how to address that issue?

Many thanks.

Best,

Konstantin

@joshuaulrich
Copy link
Owner

Hi Konstantin, this isn't the right place to ask your question. You can try Stackoverflow or the R-SIG-Finance mailing list. You also need to provide a minimal reproducible example.

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

5 participants