Questions tagged [xts]

xts is an R package that contains an eXtensible Time Series class and methods. xts extends and behaves like zoo.

xts is an package for analysis. It provides uniform handling of R's different time-based data classes by extending the package.

Repositories

Vignettes

Other resources

Related tags

1987 questions
59
votes
5 answers

Convert data frame with date column to timeseries

I've got a data frame with the following data: >PRICE DATE CLOSE 1 20070103 54.700 2 20070104 54.770 3 20070105 55.120 4 20070108 54.870 5 20070109 54.860 6 20070110 54.270 7 20070111 54.770 8 20070112 55.360 9 …
roirodriguez
  • 1,685
  • 2
  • 17
  • 31
57
votes
11 answers

Converting a data frame to xts

I'm trying to convert a data frame to xts object using the as.xts()-method. Here is my input dataframe q: q t x 1 2006-01-01 00:00:00 1 2 2006-01-01 01:00:00 2 3 2006-01-01 02:00:00 3 str(q) 'data.frame': 10…
user442446
  • 1,099
  • 3
  • 12
  • 13
48
votes
3 answers

Return data subset time frames within another timeframes?

There are very nifty ways of subsetting xts objects. For example, one can get all the data for all years, months, days but being strictly between 9:30 AM and 4 PM by doing: my_xts["T09:30/T16:00"] Or you can get all the observations between two…
Alex
  • 19,533
  • 37
  • 126
  • 195
42
votes
13 answers

Basic lag in R vector/dataframe

Will most likely expose that I am new to R, but in SPSS, running lags is very easy. Obviously this is user error, but what I am missing? x <- sample(c(1:9), 10, replace = T) y <- lag(x, 1) ds <- cbind(x, y) ds Results in: x y [1,] 4 4 [2,]…
Btibert3
  • 38,798
  • 44
  • 129
  • 168
38
votes
6 answers

How can I change XTS to data.frame and keep Index?

I have an XTS timeseries in R of the following format and am trying to do some processing, subsetting and re-arranging before exporting as a CSV for work in another program. head(master_1) S_1 2010-03-03 00:00:00 2.8520 2010-03-03…
phrozenpenguin
  • 677
  • 2
  • 7
  • 7
28
votes
4 answers

How to aggregate a dataframe by week?

Consider the following example library(tidyverse) library(lubridate) time <- seq(from =ymd("2014-02-24"),to= ymd("2014-03-20"), by="days") set.seed(123) values <- sample(seq(from = 20, to = 50, by = 5), size = length(time), replace = TRUE) df2 <-…
ℕʘʘḆḽḘ
  • 18,566
  • 34
  • 128
  • 235
27
votes
2 answers

What does useMethod mean here?

One of the kool things about R is if I type the function name I get to see the implementation. But this one is confusing me, recursively: > library(xts) > align.time function (x, ...) { UseMethod("align.time") } x…
Darren Cook
  • 27,837
  • 13
  • 117
  • 217
26
votes
3 answers

Forecasting time series data

I've done some research and I am stuck in finding the solution. I have a time series data, very basic data frame, let's call it x: Date Used 11/1/2011 587 11/2/2011 578 11/3/2011 600 11/4/2011 599 11/5/2011 678 11/6/2011 …
george willy
  • 1,693
  • 8
  • 22
  • 26
25
votes
2 answers

Access zoo or xts index

I am using zoo objects, buy my question also applies to xts objects. It looks to me like it is a one column vector with an index. In my case the index is the vector of dates and the one column vector my data. All is good except that I would like to…
feschet
  • 251
  • 1
  • 3
  • 3
21
votes
1 answer

Longer object length is not a multiple of shorter object length?

I don't understand why R gives me a warning about "Longer object length is not a multiple of shorter object length" I have this object which is generated by doing an aggregate over an xts series giving the weekday median: u <- aggregate(d,…
tovare
  • 4,027
  • 5
  • 29
  • 30
17
votes
3 answers

Reading csv with date and time

I am working in R and reading csv which has date and time in its first column. I want to import this csv file in R first and then convert it to zoo obect. I am using the code in R EURUSD <- as.xts(read.zoo("myfile.csv",sep=",",tz="",header=T)) My…
user395882
  • 665
  • 2
  • 7
  • 16
17
votes
4 answers

Grouping every n minutes with dplyr

I have a dataset containing 10 events occuring at a certain time on a given day, with corresponding value for each event: d1 <- data.frame(date = as.POSIXct(c("21/05/2010 19:59:37", "21/05/2010 08:40:30", "21/05/2010…
Steven Beaupré
  • 21,343
  • 7
  • 57
  • 77
16
votes
1 answer

Why apply() returns a transposed xts matrix?

I want to run a function on all periods of an xts matrix. apply() is very fast but the returned matrix has transposed dimensions compared to the original object: > dim(myxts) [1] 7429 48 > myxts.2 = apply(myxts, 1 , function(x) { return(x) }) >…
Robert Kubrick
  • 8,413
  • 13
  • 59
  • 91
16
votes
2 answers

Converting data.frame to xts order.by requires an appropriate time-based object

I have this following data frame: > head(table,10) Date Open High Low Close Volume Adj.Close 1 2014-04-11 32.64 33.48 32.15 32.87 28040700 32.87 2 2014-04-10 34.88 34.98 33.09 33.40 33970700 33.40 3 2014-04-09 34.19…
asosnovsky
  • 2,158
  • 3
  • 24
  • 41
14
votes
2 answers

Which is the best method to apply a script repetitively to n .csv files in R?

My situation: I have a number of csv files all with the same suffix pre .csv, but the first two characters of the file name are different (ie AA01.csv, AB01.csv, AC01.csv etc) I have an R script which I would like to run on each file. This file…
n.e.w
  • 1,128
  • 10
  • 23
1
2 3
99 100