xts

ggplot2: yearmon scale and geom_bar

走远了吗. 提交于 2020-08-27 06:49:28
问题 More than a solution I'd like to understand the reason why something which should be quite easy, it's actually not. [I am borrowing part of the code from a different post which touched on the issue but it ended up with a solution I didn't like] library(ggplot2) library(xts) library(dplyr) library(scales) csvData <- "dt,status 2015-12-03,1 2015-12-05,1 2015-12-05,0 2015-11-24,1 2015-10-17,0 2015-12-18,0 2016-06-30,0 2016-05-21,1 2016-03-31,0 2015-12-31,0" tmp <- read.csv(textConnection(csvData

convert a irregular time series of a data table with factors into a regular time series in R

风格不统一 提交于 2020-06-17 09:07:12
问题 I am trying to convert a irregular time series of a data table into a regular time series. My data looks like this library(data.table) dtRes <- data.table(time = c(0.1, 0.8, 1, 2.3, 2.4, 4.8, 4.9), abst = c(1, 1, 1, 0, 0, 3, 3), farbe = as.factor(c("keine", "keine", "keine", "keine", "keine", "rot", "blau")), gier = c(2.5, 2.5, 2.5, 0, 0, 3, 3), goff = as.factor(c("haus", "maus", "toll", "maus", NA, "maus", "maus")), huft = as.factor(c(NA, NA, NA, "wolle", "wolle", "holz", "holz")), mode = c

Preserve timestamp after decomposing xts in R

冷暖自知 提交于 2020-06-11 05:15:12
问题 I have an xts timeseries called hourplot in R with a period of 24 (hourly data) over two weeks, indexed by timestamp objects of POSIXlt class, like the following: > dput(hourplot) structure(c(1, 1, 1, 1, 1, 1, 1.11221374045802, 1.3368, 1.18, 1.0032, 1, 1, 1, 1, 1, 1, 1.0736, 1.2536, 1, 1.0032, 1.1856, 1.0048, 1, 1, 1, 1, 1, 1, 1, 1, 1.04045801526718, 1.20229007633588, 1.00229007633588, 1, 1, 1, 1, 1, 1, 1, 1.1152, 1.008, 1, 1, 1.2648, 1.1832, 1, 1, 1, 1, 1, 1, 1, 1.0424, 1.2952, 1.6496, 1

How does one compute the mean of weekly data by column using R?

纵饮孤独 提交于 2020-02-23 06:33:05
问题 I have a data frame of daily data: df with four columns: Date, A, B, C and am trying to get the mean of weekly data by column. I tried: library(xts) xdf <- xts(df[ ,-1],as.Date(df$Date)) apply.weekly(xdf,mean) but this gives me the mean of all the columns. I need the weekly means of each column. Thank you for your help 回答1: First get some data (I'll use a data.frame since that's what you're using, but I really suggest you use a time series class for time series objects) getSymbols("SPY", src=

Plotting an xts object using ggplot2

爷,独闯天下 提交于 2020-01-23 08:33:51
问题 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 <- as.numeric(c(3, 4, 5, 6, 5)) new_df <- data_frame(dates, value) new_df$dates <- as.Date(dates) new_df <- as.xts(new_df[,-1], order.by = new_df$dates) Now I try to plot it using ggplot2: ggplot(new_df, aes(x = index, y = value)) + geom_point() I get the following error: Error in (function (..., row.names = NULL,