I appreciate if anyone can help me, I have a table as follow,> rateDATE 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
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>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,> rateDATE 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
Martin Maechler
2004-Nov-24 09:47 UTC
[R] Posting to 2 mailing lists {was "How to extract data?"}
You posted the referenced message to both R-help and R-sig-finance. Please do *not* post to more than one R-list! Please do *not* post to more than one R-list! Please do *not* post to more than one R-list! Please decide if something is specific for an R-SIG-<foo> list or if it belongs to R-help (or R-devel) and post to one and only one mailing list! We had another mess recently with this by a posting to both R-help and R-sig-gui (and I think another one where even 3 mailing lists where affected). The whole thing is a particular impoliteness to all those people -- often the nice helpers! -- who are subscribed to more than one of the implied lists. Chosing one list, the discussion thread will be archived/seen/read consistently both on the server archives and people's mail/news boxes. - If the thread should be *diverted* to another list, there could be *one* overlap message (posting to both), where the move should be announced - If you deem it relevant, you can still alert the readers of one list to a "hot topic" on another list, e.g., by posting an URL to the starting message in an (online) archive. Martin Maechler, ETH Zurich PS: Of course, I've been tempted for a moment to post this to all R- mailing lists ;-) :-)