Quantcast
Channel: Active questions tagged xts - Stack Overflow
Browsing latest articles
Browse All 43 View Live

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 <-...

View Article



how to shift an xts time series to the left in r?

I am trying to shift one column of an xts time series to the left in R (please see the code below). The lag shifts nicely to the right, but I want it to line up with the rolling mean. Using a negative...

View Article

error in xts - "'order.by' cannot contain 'NA', 'NaN', or 'Inf'"

I am trying to convert a csv data.frame into an xts and keep getting the following error:the file is a csv daily stock data downloaded from Yahoo Finance for "AAPL"Here is what I did so...

View Article

Aggregate daily level data to weekly level in R

I have a huge dataset similar to the following reproducible sample data. Interval value1 2012-06-10 5522 2012-06-11 48503 2012-06-12 46424 2012-06-13 41325 2012-06-14 41906 2012-06-15 41867 2012-06-16...

View Article

Calculate Return with R

I'm a new to R. I have an Excel file called "bitcoin" which contains two columns: "date" and "BTC.Close". I've imported the data into R and transformed it into an xts object. However, I'm encountering...

View Article


Data table output looks very different than xts output

I'm having trouble viewing a data table in a tabular format. If I use the PCRA package and export a dataset as an xts object (see the minimal example below), the xts object resembles a...

View Article

How to aggregate a dataframe by week?

Consider the following examplelibrary(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 =...

View Article

How to round trip (to and from a .csv file) with an xts object?

Trying to do a round trip (write/read) with an xts object. read.zoo() returns a data frame! Converting this to an xts fails.How do I make it an xts object?library(quantmod)from <- "2016-01-01" ##...

View Article


Obtaining last Friday's date

I can get today's date:Sys.Date( )But how do I get last Friday's date?I tried:library(xts)date1 <- Sys.Date( ) to.weekly(date1 )But this gives an error.

View Article


How do I debug for different inputs in R when dput() results are seemingly...

I've been wrangling data in Python to comply with the documentation for the "BGVAR" package in R.It states that for the bgvar class I need to input Data as a list of dataframes where each item is named...

View Article

Image may be NSFW.
Clik here to view.

XTS in R studio

I'm reading a binary output file of a program using a R package. When I executed the below line of code I see a data structure as shown in the snapshot under the 'Environment' tab of R Studio.output...

View Article

Plotting an xts object using ggplot2

I'm wanting to plot an xts object using ggplot2 but getting an error. Here is what I'm doing: dates <- c("2014-10-01", "2014-11-01", "2014-12-01", "2015-01-01", "2015-02-01")value <-...

View Article

XTS: split FX intraday bar data by trading days

I want to apply a function to 20 trading days worth of hourly FX data (as one example amongst many).I started off with rollapply(data,width=20*24,FUN=FUN,by=24). That seemed to be working well, I could...

View Article


How to create a variable based on a given growth rate using xts?

I want to create a variable based on a given growth rate, which is in another variable, starting from a base of 1. Below is an example. I tried two methods, either applying growth rate to lagged value...

View Article

vectorization in xts is there a simple solution

set.seed(2)library(xts)x <- sample(1:5,10,replace = T)x.xts <- xts(x, order.by = seq(as.POSIXct(Sys.time()), length = 10, by = "min"))I have xts object x.xts and i want apply to him vectorized...

View Article


OpenSSL3.1 C example of AES-XTS using EVP interfaces Unable to segment data...

For AES-XTS encryption, I want to perform segmented input calculations on the data, but it has a problem.#include <openssl/evp.h>#include <openssl/rand.h>#include <stdio.h>#include...

View Article

Image may be NSFW.
Clik here to view.

How to transform/simplify a data.frame with timeseries in columns to an...

How do I go from image #1 to #2 in R ?I would expect this transformation to be so common in timeseries analysis that xts::, zoo:: or data.table:: would have a pre-built routine to make the series...

View Article


Auto.arima from forecas-Different results for Zoo object and.xts object?

I have time series of Covid-19 death cases which is only weekdays without weekend. I created it in R as .zoo object. But since some packages work better with time series I created it as .xts object as...

View Article

Filtering a xts object from one year to the next

If I have a 10-year daily xts time series, starting on 1985-01-01 and ending on 1994-12-31, how can I calculate the sum of values for the interval starting on Nov 1 and ending on Mar 31 of the next...

View Article

Image may be NSFW.
Clik here to view.

Add a subtitle to plot.xts

Is there a way to add a subtitle like in base plot to plot.xts?plot(xts(rnorm(100), order.by = as.Date(1:100)), sub = "Subtitle")plot(rnorm(100), sub = "Subtitle", type = "l")

View Article

why don't the names change to those that were specified in the date frame?

I wrote a simple function that combines all indicators from the TTR package, but not all indicators have names that have changed as I specified in the dataframe.for example, TTR::chaikinVolatility...

View Article


How to use gstar package of R for spatio-tempral analysis?

I want to perform a spatio-temporal analysis by highlighting spatial as well as temporal dependencies of the data (I have a 'weight matrix' highlighting spatial dependencies of the counties) on the...

View Article


how to build multiple sliding windows from xts object using rollapply function

I have a matrix with two columns where each column is a variable. I'm building two sliding windows of size 3data <- matrix(1:20,ncol = 2, dimnames = list(NULL, c("var1","var2")))> data var1 var2...

View Article

list of xts objects back to list after merge

I have a list of xts objectsset.seed(1)library(xts)tm <- Sys.time()+1:10f <- function(){ m <- matrix(1:40,ncol = 4, dimnames = list(NULL, paste0("x",1:4))) xts(m ,tm)[-sample(10,sample(9,1))]}...

View Article

printing an xts object

I am trying to create an xts object of this S&P500 sample. This is the code I am using:sp500 <- read.csv2("SP500.csv", stringsAsFactors = F, header = T, sep = ",", na.strings = ".")sp500$DATE...

View Article


Plot multiple series on a dygraph

I'm trying to plot multiple series on a dygraph line chart.The df is of this structure:structure(list(Date = structure(c(4216, 4216, 4217, 4217, 4218, 4218, 4219, 4219, 4220, 4220, 4221, 4221, 4222,...

View Article

Is it possible to get the specific index of occurence when working with...

Assuming I worked with meteorological observations and wanted to know not only the daily maximum value but also the relevant timestamp, describing when this value was observed, is it possible to...

View Article

Aggregate xts coredata in case of duplicate indices

Assuming I have the following xts object with duplicated time information:library(xts)x <- xts(1:5, c("2024-04-19", "2024-04-19", "2024-04-20", "2024-04-21", "2024-04-21") |> as.Date())x#>...

View Article

How Do You Execute If-Then Logic On All The Columns Of An xts object in R

I have an xts object with multiple columns in R and I want to convert all the numbers larger than, say, 0.05 to NA (or -99 or something like that).To get some data to execute on please do the...

View Article



decomposition hourly timeseries

I have the following time series data example: structure(list(cycle_rounded = structure(c(1604534400, 1604538000, 1604541600, 1604545200, 1604548800, 1604552400, 1604556000, 1604559600, 1604563200,...

View Article
Browsing latest articles
Browse All 43 View Live




Latest Images