Re: [R] Calculating length of consecutive sequences within a vector

2012-03-09 Thread Jorge Molinos
Thanks, rle is what I was looking for.

Jorge




From: R. Michael Weylandt [michael.weyla...@gmail.com]
Sent: 08 March 2012 16:29
To: Jorge Molinos
Cc: r-help@R-project.org
Subject: Re: [R] Calculating length of consecutive sequences within a vector

rle should get you started.

Michael

On Thu, Mar 8, 2012 at 9:35 AM, Jorge Molinos jgarc...@tcd.ie wrote:
 Hi all,

 I have a nx1 logical array of zeros and ones and I want to calculate the 
 individual lengths of all 1-consecutive sequences contained in it. Is there 
 an easy quick way to do this in R? So, if I have a vector such as

 1110011011110

 I would like to get (1) 3, (2) 2, (3) 1, (4) 7

 Any help would be appreciated! thanks!

 Jorge

[[alternative HTML version deleted]]

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Calculating length of consecutive sequences within a vector

2012-03-08 Thread Jorge Molinos
Hi all,

I have a nx1 logical array of zeros and ones and I want to calculate the 
individual lengths of all 1-consecutive sequences contained in it. Is there an 
easy quick way to do this in R? So, if I have a vector such as

1110011011110

I would like to get (1) 3, (2) 2, (3) 1, (4) 7

Any help would be appreciated! thanks!

Jorge

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Calculate a function repeatedly over sections of a ts object

2012-01-30 Thread Jorge Molinos

Thank you very much Mike. The script is working now.

Jorge





From: R. Michael Weylandt [michael.weyla...@gmail.com]
Sent: 30 January 2012 04:29
To: Jorge Molinos; r-help
Subject: Re: [R] Calculate a function repeatedly over sections of a ts object

Sorry, that last line should read:

FUN=function(z){
  lz - length(z)
  SDF(z,method=lag window,
window=taper(type=parzen,n.sample=lz,cutoff= 2*sqrt(lz)), npad=2*lz)
}

On Sun, Jan 29, 2012 at 11:29 PM, R. Michael Weylandt
michael.weyla...@gmail.com wrote:
 It's customary to keep the list cc'd.

 I can't run your code without the data, but it does seem to me that
 your problem is in the FUN argument, as you guess.

 You have:

 FUN=function(z) SDF(adezoo,method=lag window,
 window=taper(type=parzen,n.sample=n.d,cutoff=(2*sqrt(n.d))),
 npad=2*n.d)

 But this function doesn't actually act on it's argument: you tell it
 to accept something called z but then it never gets told to do
 anything to z. Perhaps you meant

 FUN=function(z) SDF(z,method=lag window,
 window=taper(type=parzen,n.sample=n.d,cutoff=(2*sqrt(n.d))),
 npad=2*n.d)

 I also worry about your use of n.d; are you sure you don't want to
 use the length of the rolling window? Something more like:

 FUN=function(z){
   lz - length(z)
   SDF(z,method=lag window,
 window=taper(type=parzen,n.sample=lz,cutoff= 2*sqrt(lz)),
 npad=2*nlz)
 }

 Does that fix it?

 Michael

 On Fri, Jan 27, 2012 at 1:06 PM, Jorge Molinos jgarc...@tcd.ie wrote:
 Hi Michael,

 Sorry, I've been trying to use rollapply with my function but it seems I 
 can't get it to work properly. The function seems to be dividing the time 
 series accordingly (every 1) and using the correct length for the time 
 window (10 years) but when I look at the results all of them are the same 
 for all the subseries which doesn't make sense. The problem has to be within 
 the FUN argument though I cannot figure out what it is. Would you mind 
 checking on the code to see if you can spot where is the problem?

 adets-ts(adeery$DA,c(adeery$Year[1],adeery$Day[1]),frequency=365)

 adezoo-as.zoo(adets)

 n.d-length(adets)

 especlist-rollapply(adezoo, width=3650, FUN=function(z) 
 SDF(adezoo,method=lag window,
window=taper(type=parzen,n.sample=n.d,cutoff=(2*sqrt(n.d))),
npad=2*n.d), by = 365, align=left)


 And these are, for example, the SDF values at the last day for each 10-y 
 subseries (all the same though they should be different as I have it verify 
 by doing the SDF step by step using the same values for the arguments within 
 the function):

 especlist1.7048
 1978(20)1.998068e-06
 1979(20)1.998068e-06
 1980(20)1.998068e-06
 1981(20)1.998068e-06
 1982(20)1.998068e-06
 1983(20)1.998068e-06
 1984(20)1.998068e-06
 1985(20)1.998068e-06
 1986(20)1.998068e-06
 1987(20)1.998068e-06

 Thanks a lot.

 Jorge


 
 From: R. Michael Weylandt [michael.weyla...@gmail.com]
 Sent: 26 January 2012 21:00
 To: Jorge Molinos
 Cc: r-help@R-project.org
 Subject: Re: [R] Calculate a function repeatedly over sections of a ts object

 I'm not sure if it's easily doable with a ts class, but the rollapply
 function in the zoo package will do this easily. (Also, I find zoo to
 be a much more natural time-series workflow than ts so it might make
 the rest of your life easier as well)

 Michael

 On Thu, Jan 26, 2012 at 2:24 PM, Jorge Molinos jgarc...@tcd.ie wrote:

 Hi,

 I want to apply a function (in my case SDF; package “sapa”) repeatedly over 
 discrete sections of a daily time series object by sliding a time window of 
 constant length (e.g. 10 consecutive years or 1825 days) over the entire ts 
 at increments of 1 time unit (e.g. 1 year or 365 days). So for example, the 
 first SDF would be calculated for the daily values of my variable recorded 
 between years 1 to 5, SDF2 to those for years 2 to 6 and so on until the 
 total length of the series is covered. How can I implement this into a R 
 script? Any help is much appreciated.

 Jorge
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Calculate a function repeatedly over sections of a ts object

2012-01-27 Thread Jorge Molinos

Thanks a lot for the suggestion. It's just what I was looking for.

Jorge



From: Gabor Grothendieck [ggrothendi...@gmail.com]
Sent: 26 January 2012 21:05
To: R. Michael Weylandt
Cc: Jorge Molinos; r-help@R-project.org
Subject: Re: [R] Calculate a function repeatedly over sections of a ts object

On Thu, Jan 26, 2012 at 4:00 PM, R. Michael Weylandt
michael.weyla...@gmail.com wrote:
 I'm not sure if it's easily doable with a ts class, but the rollapply
 function in the zoo package will do this easily. (Also, I find zoo to
 be a much more natural time-series workflow than ts so it might make
 the rest of your life easier as well)


rollapply does have ts and default methods in addition to a zoo method.

--
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Calculate a function repeatedly over sections of a ts object

2012-01-26 Thread Jorge Molinos

Hi,

I want to apply a function (in my case SDF; package “sapa”) repeatedly over 
discrete sections of a daily time series object by sliding a time window of 
constant length (e.g. 10 consecutive years or 1825 days) over the entire ts at 
increments of 1 time unit (e.g. 1 year or 365 days). So for example, the first 
SDF would be calculated for the daily values of my variable recorded between 
years 1 to 5, SDF2 to those for years 2 to 6 and so on until the total length 
of the series is covered. How can I implement this into a R script? Any help is 
much appreciated.

Jorge
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.