[R] How to get multiple partial matches?

Sarah Tucker sltucker15 at yahoo.com
Thu Sep 7 01:39:38 CEST 2006


Hi, 

I'm very new to R, and am not at all a software
programmer of any sort.    I appreciate any help you
may have.  I have figured out how to get my data into
a dataframe and order it alphabetically according to a
particular column.  Now, I would like to seperate out
certain rows based on partial character matches.  Here
is an (extremely) abreviated example of my data set

        Probe Ch1 Median - B Ch1 Mean - B
72     5S_F_1            501          567
7700   5S_F_2            338          611
7517   5S_F_3            412          467
10687  5S_F_4            380          428
4870   5S_F_5            315          368
6035   5S_F_6            300          359
3826   5S_F_7            350          386
8754   5S_F_8            450          473
6399   5S_F_9            439          494
749   5S_F_10            334          384

I would like to be able to select out all rows with,
for example, "5S_F_" in the Probe column (there are
non-"5S_F_" containing values in the real, larger data
set).

I think pmatch does this for instances where there is
only 1 match, but I would like to recover all the
matches.  I have tried to use charmatch, match,
pmatch, agrep and grep for this purpose, but with no
luck.

When I grep for "5S_F_" with value = T, I get
"character(0)"
Adding wildcards (either "*" or ".") does not change
this outcome.

I thought maybe the underscores were messing it up, so
I tried to grep "5S*" with value = T, and I get a long
list of numbers back

[1] "55"   "95"   "56"   "57"   "58"   "59"   "65"  
"75"   "85"   "105" 
  [11] "115"  "125"  "135"  "5"    "5"    "5"    "5"  
 "5"    "5"    "5"  

These numbers make no sense to me.  They don't seem to
correlate with where the "5S"'s occur in the
dataframe, and they don't look like any values in the
Probe column (there are no numeric vaules in the Probe
column, just strings of character digit combinations).

How can I select out all the rows with the same
partial character match?



More information about the R-help mailing list