zoo

How to sort by year and month in R (using as.yearmon from zoo package)

偶尔善良 提交于 2019-12-13 05:59:49
问题 I'm trying to sort a vector with year and month information. I'm getting year and month from a Date type variable. Here's an example of what I'm trying to accomplish: example <- as.Date(c("2010-04-22", "2010-04-26", "2010-04-26", "2010-06-04", "2010-06-07", "2010-06-18", "2010-06-21", "2010-07-14", "2010-07-16", "2010-07-30", "2010-08-20")) mes_ano <- as.character(as.yearmon(as.Date(example))) mes_ano <- factor(mes_ano, levels = c(unique(mes_ano), "mai 2010", "set 2010", "out 2010", "nov 2010

Unable to install package zoo

不打扰是莪最后的温柔 提交于 2019-12-13 02:58:52
问题 I am trying to install zoo package using: install.packages("zoo") I am getting the following error: package ‘zoo’ successfully unpacked and MD5 sums checked Warning in install.packages : cannot remove prior installation of package ‘zoo’ The downloaded binary packages are in C:\Users\user\AppData\Local\Temp\Rtmpaa1iAI\downloaded_packages Any assistance out there. Newbie in R 来源: https://stackoverflow.com/questions/46012471/unable-to-install-package-zoo

R: Rollapply lm regression on zoo matrix objects

谁说胖子不能爱 提交于 2019-12-12 20:47:34
问题 I would like to perform a rolling regression using lm on many pairs of data series within a single zoo object. While I am able to perform a rolling regression on one single pair of data series in a zoo object by the following codes: FunLm <- function(x,Param,Days) coef(lm(AAA ~ Z, data = as.data.frame(x), weights=Param*(seq(Days,1,by=-1)))) DataLmCoef <- rollapplyr(Data, Days, FunLm, Param, Days, by.column = FALSE) with zoo of this structure: Z AAA 2012-07-01 1 853 2012-07-04 2 864 2012-07-05

From daily time series to weekly time series in R xts object

一世执手 提交于 2019-12-12 20:34:09
问题 I'm using the zoo and xts package for analysing financial data. ts package is not very suitable since financial series have weekend with no data available. I read about the apply function availbale in the xts package apply.daily(x, FUN, ...) apply.weekly(x, FUN, ...) apply.monthly(x, FUN, ...) apply.quarterly(x, FUN, ...) apply.yearly(x, FUN, ...) this apply function over calendar periods and thought that something like that will work in order to get the end of week value but it seems not to

Coercing a POSIXct object to Date object

不打扰是莪最后的温柔 提交于 2019-12-12 11:18:43
问题 Reproducible code: # Loading quantmod library(quantmod) # Please, put in R this structure a <- structure(c(2.4, 2.35, 2.44, 2.44, 2.31, 2.32, 2.41, 2.43, 2.46, 2.42, 2.45, 2.39, 2.3, 2.41, 2.33, 2.37, 2.38, 2.4, 2.275, 2.235, -0.0300000000000002, -0.0499999999999998, 0.0899999999999999, 0, -0.13, 0.00999999999999979, 0.0900000000000003, 0.02, 0.0299999999999998, -0.04, 0.0300000000000002, -0.0600000000000001, -0.0900000000000003, 0.11, -0.0800000000000001, 0.04, 0.00999999999999979, 0.02, -0

Forcing full weeks with apply.weekly()

狂风中的少年 提交于 2019-12-12 10:48:05
问题 I'm trying to figure out what xts (or zoo) uses as the time after doing an apply.period. Consider the following: > myTs = xts(1:10, as.Date(1:10, origin = '2012-12-1')) > apply.weekly(myTs, colSums) [,1] 2012-12-02 1 2012-12-09 35 2012-12-11 19 I think the '2012-12-02' means "for the week ending 2012-12-02, the sum is 1". So basically the time is the end of the week. But the problem is with that "2012-12-11" - I think what it's doing is saying that the 11th is the last day of the week that

Using dplyr summary function on yearmon from zoo

白昼怎懂夜的黑 提交于 2019-12-12 06:35:50
问题 I have a data frame with values associated to a year and month. I use yearmon class from zoo package to store the year-month info. My aim is to count the average of those values from the same year-month. However, using dplyr seems to give me an error. The variable tst below for reproduction > str(tst) 'data.frame': 20 obs. of 2 variables: $ n : int 23 24 26 27 26 23 19 19 22 22 ... $ ym:Class 'yearmon' num [1:20] 2004 2004 2004 2004 2004 ... > dput(tst) structure(list(n = c(23L, 24L, 26L, 27L

Quotation marks when zoo to xts using as.xts() in R

淺唱寂寞╮ 提交于 2019-12-12 05:47:49
问题 When transforming the below data (class "zoo") into xts, I use returns.xts<-as.xts(returns) . The effect is to add quotation marks around the new Data. And then becomes unusable in functions. Why is this? class("zoo") UK.EQUITY EUR.EQUITY NA.EQUITY ASIA.EQUITY JPN.EQUITY EM.EQUITY WORLD.EQUITY.EX.UK 2006-04-30 0.010552982 -0.003337229 -0.033739353 0.025092643 -0.020920633 0.020016007 -0.021165353 2006-05-31 -0.048962517 -0.071924029 -0.059684763 -0.102475485 -0.098121902 -0.141877111 -0

R - Loop in matrix

不羁的心 提交于 2019-12-12 05:15:40
问题 I have two variables, the first is 1D flow vector containing 230 data and the second is 2D temperature matrix (230*44219). I am trying to find the correlation matrix between each flow value and corresponding 44219 temperature. This is my code below. Houlgrave_flow_1981_2000 = window(Houlgrave_flow_average, start = as.Date("1981-11-15"),end = as.Date("2000-12-15")) > str(Houlgrave_flow_1981_2000) ‘zoo’ series from 1981-11-15 to 2000-12-15 Data: num [1:230] 0.085689 0.021437 0.000705 0 0.006969

Rolling lagged differences

雨燕双飞 提交于 2019-12-12 03:58:18
问题 Ok so I am looking to create rolling lagged differences in R. vec <- c(43.79979, 44.04865, 44.17308, 44.54638, 44.79524, 44.79524, 44.79524, 44.42195, 44.54638, 44.79524, 44.42195, 43.30206, 43.30206, 43.17764, 43.30206) > length(vec) [1] 15 This is what I have tried so far: vec1 <- rollapply(vec, width = 2, fill = NA, FUN = diff) This gives this output: [1] 0.24886 0.12443 0.37330 0.24886 0.00000 0.00000 -0.37329 0.12443 0.24886 -0.37329 -1.11989 0.00000 -0.12442 0.12442 NA > length(vec1) [1