Re: [R] overlapping pattern match (errata 2.0)

2003-03-29 Thread james . holtman

Another way to find all the multiple occurances of a character in a string
is to use 'rle':

 x.s - 'aaabbcdeeeggiijjysbbddeffghjjjsdk'
 x - unlist(strsplit(x.s, NULL))
 x
 [1] a a a b b c d e e e f f f f g g i
i j
[20] j y s b b d d e f f g h j j j s d
k k
[39] k k k
 rle(x)
Run Length Encoding
  lengths: int [1:21] 3 2 1 1 3 4 2 2 2 1 ...
  values : chr [1:21] a b c d e f g i j y s b d
e f g ...


When the lengths are 1, the corresponding 'values' are the repeated
characters.




   

  FMGCFMGC 

  [EMAIL PROTECTED]  To:   [EMAIL PROTECTED] 
 
  Sent by: cc:   [EMAIL PROTECTED] 
 
  [EMAIL PROTECTED]Subject:  Re: [R] overlapping pattern 
match (errata 2.0)
  ath.ethz.ch  

   

   

  03/28/03 17:36   

   

   





well! excuse me again but...

your.string - aaacdf
nc1 - nchar(your.string)-1
x - unlist(strsplit(your.string, NULL))  CORRECT
x2 - c()
for (i in 1:nc1)
x2 - c(x2, paste(x[i], x[i+1], sep=))  ERRATA 2
cat(ocurrences of aa in your.string: , length(grep(aa, x2)),
sep=, fill=TRUE)

Fran

PD: sorry again

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help




--
NOTICE:  The information contained in this electronic mail transmission is
intended by Convergys Corporation for the use of the named individual or
entity to which it is directed and may contain information that is
privileged or otherwise confidential.  If you have received this electronic
mail transmission in error, please delete it from your system without
copying or forwarding it, and notify the sender of the error by reply email
or by telephone (collect), so that the sender's address records can be
corrected.

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] overlapping pattern match

2003-03-28 Thread Jerome Asselin

Here's a way.

string - aaacdf
pattern - aa
nstring - nchar(string)
npattern - nchar(pattern)
stringlist - substring(string, 1:(nstring-npattern+1), npattern:nstring)
sum(stringlist==pattern)

Also, have a look at: pmatch, charmatch, grep, sub, gsub, regexpr, chartr. I 
couldn't find a simple function to do what you want.

Hope this helps.

Jerome

On March 27, 2003 05:34 pm, Yiping Fan wrote:
 Content-Length: 360
 Status: R
 X-Status: N

 Hi, all,
  I have a string like  aaacdf,  I want to find how many aa in the
 string. Obviously, It is 2 in this case.  it is easy to do in Perl, but how
 to do such  overlapping match in R or Splus.  Thanks!

 Y.Fan

 __
 [EMAIL PROTECTED] mailing list
 https://www.stat.math.ethz.ch/mailman/listinfo/r-help

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] overlapping pattern match

2003-03-28 Thread FMGCFMGC
try with this:

your.string - aaacdf
nc1 - nchar(your.string)-1
x - unlist(strsplit(cadena, NULL)) 
x2 - c()
for (i in 1:nc1)
  x2 - c(x2, paste(x2[i], x2[i+1], sep=))
cat(ocurrences of aa in your.string:, length(grep(aa, x2)),
  sep=, fill=TRUE)

Hope it helps!
Fran

--- original message ---
Hi, all,
 I have a string like  aaacdf,  I want to find how many aa in 
the string. Obviously, It is 2 in this case.  it is easy to do in Perl, 
but how to do such  overlapping match in R or Splus.  Thanks!

Y.Fan

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] overlapping pattern match

2003-03-27 Thread Yiping Fan
Hi, all,
 I have a string like  aaacdf,  I want to find how many aa in the
string. Obviously, It is 2 in this case.  it is easy to do in Perl, but how
to do such  overlapping match in R or Splus.  Thanks!

Y.Fan

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help