Displaying 20 results from an estimated 10000 matches similar to: "Rolling window difference for zoo time series"
2018 Apr 24
0
Rolling window difference for zoo time series
Zoo_TS/lag(Zoo_TS) - 1
On Tue, Apr 24, 2018 at 9:29 PM, Christofer Bogaso <
bogaso.christofer at gmail.com> wrote:
> Hi,
>
> I have a 'zoo' time series as below :
>
> Zoo_TS = zoo(5:1, as.Date(Sys.time())+0:4)
>
> Now I want to calculate First order difference of order 1, rolling
> window basis i.e.
>
> (Zoo_TS[2] - Zoo_TS[1] ) / Zoo_TS[1]
>
2017 Aug 10
3
Zoo rolling window with increasing window size
Hi Joshua, thanks for your prompt reply. However as I said, sum()
function I used here just for demonstrating the problem, I have other
custom function to implement, not necessarily sum()
I am looking for a generic solution for above problem.
Any better idea? Thanks,
On Fri, Aug 11, 2017 at 12:04 AM, Joshua Ulrich <josh.m.ulrich at gmail.com> wrote:
> Use a `width` of integer index
2017 Aug 10
0
Zoo rolling window with increasing window size
Replace "sum" with your custom function's name. I don't see any
reason why that wouldn't work, and the problem with my solution is not
clear in your response.
r <- rollapplyr(x, seq_along(x), yourCustomFunctionGoesHere)
On Thu, Aug 10, 2017 at 1:39 PM, Christofer Bogaso
<bogaso.christofer at gmail.com> wrote:
> Hi Joshua, thanks for your prompt reply. However
2017 Aug 10
2
Zoo rolling window with increasing window size
Hi again,
I am wondering there is any function for 'zoo' time series, where I
can apply a user defined function rolling window basis, wherein window
size is ever increasing i.e. not fixed. For example, let say I have
below user defined function and a zoo time series :
> library(zoo)
> UDF = function(x) sum(x)
> TS = zoo(rnorm(10), seq(as.Date('2017-01-01'),
2017 Aug 10
0
Zoo rolling window with increasing window size
Use a `width` of integer index locations. And you likely want =
"right" (or rollapplyr(), as I used).
R> set.seed(21)
R> x <- rnorm(10)
R> rs <- rollapplyr(x, seq_along(x), sum)
R> cs <- cumsum(x)
R> identical(rs, cs)
[1] TRUE
On Thu, Aug 10, 2017 at 1:28 PM, Christofer Bogaso
<bogaso.christofer at gmail.com> wrote:
> Hi again,
>
> I am
2011 Apr 06
2
A zoo related question
Dear all, please consider my following workbook:
library(zoo)
lis1 <- vector('list', length = 2)
lis2 <- vector('list', length = 2)
lis1[[1]] <- zooreg(rnorm(20), start = as.Date("2010-01-01"), frequency = 1)
lis1[[2]] <- zooreg(rnorm(20), start = as.yearmon("2010-01-01"), frequency =
12)
lis2[[1]] <- matrix(1:40, 20)
lis2[[2]] <-
2010 Jul 10
7
Need help on date calculation
Hi all, please see my code:
> library(zoo)
> a <- as.yearmon("March-2010", "%B-%Y")
> b <- as.yearmon("May-2010", "%B-%Y")
>
> nn <- (b-a)*12 # number of months in between them
> nn
[1] 2
> as.integer(nn)
[1] 1
What is the correct way to find the number of months between "a" and "b",
still
2009 Jul 01
1
A problem on zoo object
I have a zoo object on daily data for 10 years. Now I want to create a list,
wherein each member of that list is the monthly observations. For example,
1st member of list contains daily observation of 1st month, 2nd member
contains daily observation of 2nd month etc.
Then for a particular month, I want to divide all observations into 3 parts
(arbitrary) and then want to calculate some statistics
2010 Jul 12
3
How to create sequence in month
Hi all, can anyone please guide me how to create a sequence of months? Here
I have tried following however couldn't get success
> library(zoo)
> seq(as.yearmon("2010-01-01"), as.yearmon("2010-03-01"), by="1 month")
Error in del/by : non-numeric argument to binary operator
What is the correct way to do that?
Thanks for your time.
2009 Jul 29
2
Importing time series
I have a time series dataset, saved in a csv file. However date-formatting is
:
7/2/1982
7/6/1982
7/7/1982
7/8/1982
7/13/1982
7/14/1982
However if I use following zoo-code, it is not reading data:
read.zoo(file="F:/data.csv", format="%m/%d/%y", header=F)
Error is
Error in read.zoo(file ="F:/data.csv", format = "%m/%d/%y", :
index contains NAs
Here
2010 Jul 07
3
Need help in handling date
Dear all, I have a date related question. Suppose I have a character string
"March-2009", how I can convert it to a valid date object like
as.yearmon("2009-01-03") in the zoo package? Is there any possibility there?
Ans secondly is there any R function which will give the names of of all
months as "LETTERS" does?
Thanks for your time.
[[alternative HTML version
2018 Mar 04
3
Change Function based on ifelse() condtion
Below is my full implementation (tried to make it simple as for demonstration)
Lapply_me = function(X = X, FUN = FUN, Apply_MC = FALSE, ...) {
if (Apply_MC) {
return(mclapply(X, FUN, ...))
} else {
if (any(names(list(...)) == 'mc.cores')) {
myList = list(...)[!names(list(...)) %in% 'mc.cores']
}
return(lapply(X, FUN, myList))
}
}
Lapply_me(as.list(1:4), function(xx) {
if (xx ==
2018 Mar 04
0
Change Function based on ifelse() condtion
The reason that it works for Apply_MC=TRUE is that in that case you call
mclapply(X,FUN,...) and
the mclapply() function strips off the mc.cores argument from the "..."
list before calling FUN, so FUN is being called with zero arguments,
exactly as it is declared.
A quick workaround is to change the line
Lapply_me(as.list(1:4), function(xx) {
to
Lapply_me(as.list(1:4),
2018 Mar 04
2
Change Function based on ifelse() condtion
My modified function looks below :
Lapply_me = function(X = X, FUN = FUN, Apply_MC = FALSE, ...) {
if (Apply_MC) {
return(mclapply(X, FUN, ...))
} else {
if (any(names(list(...)) == 'mc.cores')) {
myList = list(...)[!names(list(...)) %in% 'mc.cores']
}
return(lapply(X, FUN, myList))
}
}
Here, I am not passing ... anymore rather passing myList
On Sun, Mar 4, 2018 at 10:37 PM,
2011 Jan 11
5
A question on dummy variable
Dear all, I would like to ask one question related to statistics, for
specifically on defining dummy variables. As of now, I have come across 3
different kind of dummy variables (assuming I am working with Seasonal
dummy, and number of season is 4):
> dummy1 <- diag(4)
> for(i in 1:3) dummy1 <- rbind(dummy1, diag(4))
> dummy1 <- dummy1[,-4]
>
> dummy2 <- dummy1
>
2018 Mar 04
2
Change Function based on ifelse() condtion
@Eric - with this approach I am getting below error :
Error in FUN(X[[i]], ...) : unused argument (list())
On Sun, Mar 4, 2018 at 10:18 PM, Eric Berger <ericjberger at gmail.com> wrote:
> Hi Christofer,
> You cannot assign to list(...). You can do the following
>
> myList <- list(...)[!names(list(...)) %in% 'mc.cores']
>
> HTH,
> Eric
>
> On Sun, Mar
2013 Mar 09
4
Calculation with date
Hello again,
Let say I have an non-negative integer vector (which may be random):
Vec <- c(0, 13, 10, 4)
And I have a date:
> Date <- as.Date(Sys.time())
> Date
[1] "2013-03-09"
Using these 2 information, I want to get following date-vector:
New_Vec <- c("2013-03-01", "2014-04-01", "2014-01-01", "2013-07-01")
Basically the
2012 Dec 14
5
A question on list and lapply
Dear all, let say I have following list:
Dat <- vector("list", length = 26)
names(Dat) <- LETTERS
My_Function <- function(x) return(rnorm(5))
Dat1 <- lapply(Dat, My_Function)
However I want to apply my function 'My_Function' for all elements of
'Dat' except the elements having 'names(Dat) == "P"'. Here I have
specified the name
2017 Aug 02
4
Extracting numeric part from a string
Hi again,
I am struggling to extract the number part from below string :
"\"cm_ffm\":\"563.77\""
Basically, I need to extract 563.77 from above. The underlying number
can be a whole number, and there could be comma separator as well.
So far I tried below :
> library(stringr)
> str_extract("\"cm_ffm\":\"563.77\"",
2012 Mar 16
4
How to start R in maximized size???
Dear all, when I start R, I want that the console window should be in
the Maximized size automatically. Can somebody help me how to achieve
that?
Thanks and regards,