s-news
[Top] [All Lists]

Re: finding substrings

To: Dave Evens <devens8765@yahoo.com>
Subject: Re: finding substrings
From: David L Lorenz <lorenz@usgs.gov>
Date: Tue, 13 Sep 2005 08:51:49 -0500
Cc: s-news@lists.biostat.wustl.edu, s-news-owner@lists.biostat.wustl.edu
In-reply-to: <20050913092327.19791.qmail@web61324.mail.yahoo.com>

Dave,
  This is probably best done by using the ability of aggregateSeries to compute running statistics.  I did not make this a generic function, but with some work, that could be done.  Here's the concrete example:

  aggregateSeries(timeSeries(c(F, F, F, T, T, F, F, T, T, F, F, T, T, T, F, F,
 F, F, F, T, T, T, F, F, T, T, F, F, T, T, T), pos=1:31)
 ,moving=5,FUN=function(x) all(x == c(F, F, T, T, F)))@data

  The idea is to create a timeSeries object of relative time, do a moving computation of length = the length of the test vector, and extract the data, which is a logical vector of length 31 - 5 + 1 (in this case). The index numbers that you want can be gotten by using which.
  Note that most everything can be converted to a timeSeries object (numeric, logical, character, factor, more?).
Dave


Dave Evens <devens8765@yahoo.com>
Sent by: s-news-owner@lists.biostat.wustl.edu

09/13/2005 04:23 AM

To
s-news@lists.biostat.wustl.edu
cc
Subject
[S] finding substrings






Dear all,

I would like to find the exact match of a
substring(/sub-vector) within a string (/vector). For
example, suppose I have

x <- c(F, F, F, T, T, F, F, T, T, F, F, T, T, T, F, F,
F, F, F, T, T, T, F, F, T, T, F, F, T, T, T)

y <- c(F, F, T, T, F)

What I would like to do is find the exact match of y
in x with possible overlapping, i.e.

return back

2 6 23

I couldn't get it to work with matchList.

Thanks for any help in advance.

Dave




                                 
__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005
http://mail.yahoo.com
--------------------------------------------------------------------
This message was distributed by s-news@lists.biostat.wustl.edu.  To
unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
the BODY of the message:  unsubscribe s-news

<Prev in Thread] Current Thread [Next in Thread>