[R] How to extract data?
Uwe Ligges
ligges at statistik.uni-dortmund.de
Wed Nov 24 09:38:41 CET 2004
james.holtman at convergys.com wrote:
>
>
>
> By 'ignore', can we delete those from the list of data? I would then
> assume that if you have a sequence of +0+0+ that you would want the last
> "+" for the increase of three.
>
> If that is the case, then do a 'diff' and delete the entries that are 0.
> Then create a new 'diff' and then use 'rle' to see what the length of the
> sequences are:
>
>
>>x <- c(1,2,2,3,3,4,3,3,2,2,2,1)
>>x
>
> [1] 1 2 2 3 3 4 3 3 2 2 2 1
>
>>x.d <- diff(x)
>>x.d
>
> [1] 1 0 1 0 1 -1 0 -1 0 0 -1
>
>>x.new <- x[c(x.d,1) != 0]
>>x.new
>
> [1] 1 2 3 4 3 2 1
>
>>x.d1 <- diff(x.new)
>>x.d1
>
> [1] 1 1 1 -1 -1 -1
>
>>rle(x.d1)
>
> Run Length Encoding
> lengths: int [1:2] 3 3
> values : num [1:2] 1 -1
Additionally, if there are differences are > 1, you might want apply
sign() before rle().
Uwe Ligges
>
> you can check the results of 'rle' to determine where the changes are.
> __________________________________________________________
> James Holtman "What is the problem you are trying to solve?"
> Executive Technical Consultant -- Office of Technology, Convergys
> james.holtman at convergys.com
> +1 (513) 723-2929
>
>
>
> ebashi
> <arshia22 at yahoo.com> To: r-sig-finance at stat.math.ethz.ch, r-help at stat.math.ethz.ch
> Sent by: cc:
> r-help-bounces at stat.m Subject: [R] How to extract data?
> ath.ethz.ch
>
>
> 11/23/2004 15:54
>
>
>
>
>
>
> I appreciate if anyone can help me,
> I have a table as follow,
>
>>rate
>
> DATE VALUE
> 1 1997-01-10 5.30
> 2 1997-01-17 5.30
> 3 1997-01-24 5.28
> 4 1997-01-31 5.30
> 5 1997-02-07 5.29
> 6 1997-02-14 5.26
> 7 1997-02-21 5.24
> 8 1997-02-28 5.26
> 9 1997-03-07 5.30
> 10 1997-03-14 5.30
> . ...... ...
> . ...... ...
> . ...... ...
> I want to extract the DATE(s) on which the VALUE has
> already dropped twice and the DATE(s) that VALUE has
> already increased for three times,( ignore where
> VALUE(i+1)-VALUE(i)=0),I try to use diff() function,
> however that works only for one increase or decrease.
>
> Sincerely,
>
> Sean
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
More information about the R-help
mailing list