s-news
[Top] [All Lists]

Re: finding substrings

To: "Dave Evens" <devens8765@yahoo.com>
Subject: Re: finding substrings
From: "Dimitris Rizopoulos" <dimitris.rizopoulos@med.kuleuven.be>
Date: Tue, 13 Sep 2005 12:10:42 +0200
Cc: <s-news@lists.biostat.wustl.edu>
References: <20050913092327.19791.qmail@web61324.mail.yahoo.com>
you could try something like this:

x <- paste(as.numeric(x), collapse = "")
y <- paste(as.numeric(y), collapse = "")

nx <- nchar(x)
ny <- nchar(y)
out <- substring(x, seq(1, nx - ny + 1), seq(ny, nx))
which(!is.na(charmatch(out, y)))


I hope it helps.

Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/16/336899
Fax: +32/16/337015
Web: http://www.med.kuleuven.be/biostat/
    http://www.student.kuleuven.be/~m0390867/dimitris.htm


----- Original Message ----- From: "Dave Evens" <devens8765@yahoo.com>
To: <s-news@lists.biostat.wustl.edu>
Sent: Tuesday, September 13, 2005 11:23 AM
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



Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm


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