try this:

> my.list <- c(7,12,3)    # set of matching numbers
> set.seed(1)
> result <- character(40)   # create empty vector
> # create  some comma separated data
> for(i in 1:40) result[i] <- paste(sample(1:20,6), collapse=',')
> # just leave it as a character vector for testing == you can convert your
data frame
> str(result)
 chr [1:40] "6,8,11,16,4,14" "19,13,12,2,4,3" "14,8,20,9,12,15"
"8,15,17,4,11,2" ...
> # find matching entries
> matches <- sapply(result, function(x){
+     .comma <- strsplit(x, ',')[[1]]  # get the fields
+     any(my.list %in% .comma)
+ })
> # print matching entries
> result[matches]
 [1] "19,13,12,2,4,3"   "14,8,20,9,12,15"  "6,8,1,7,14,20"
"10,12,9,4,14,11"  "16,3,14,7,18,10"
 [6] "2,20,6,9,11,7"    "7,20,9,16,14,6"   "16,19,8,13,7,5"
"16,4,13,3,19,17"  "5,2,12,15,13,18"
[11] "6,19,12,4,3,8"    "19,12,18,13,6,7"  "3,1,13,2,8,10"
"20,10,9,3,13,7"   "13,11,6,8,9,3"
[16] "15,7,12,20,14,6"  "8,18,12,13,10,14" "6,4,16,9,15,3"
"16,14,17,10,12,6" "3,18,6,11,2,13"
[21] "7,15,5,4,9,18"    "4,10,11,3,5,18"   "13,19,18,6,5,3"
"7,10,17,9,5,1"    "9,17,7,3,6,10"
[26] "8,14,13,10,7,16"
>



On 2/19/07, Johannes Graumann <[EMAIL PROTECTED]> wrote:
>
> On Monday 19 February 2007 17:49, jim holtman wrote:
> > have you tried 'unlist(strsplit(....))'?    The 'unlist' will probably
> give
> > you more values than you have rows, so it would be good if you could
> > explain what it is you are trying to do.
> I want to isolate a data frame containing all rows of 'dataframe' which
> contain a member of 'list' in the field 'Field', which itself is a comma
> separated list of entries.
>
> Better this (know in brain ...)?
>
> Joh
>
> > On 2/19/07, Johannes Graumann <[EMAIL PROTECTED]> wrote:
> > > Hello again,
> > >
> > > I'm trying to do the following:
> > >
> > > subset(dataframe,list %in% strsplit(dataframe[[Field]],","))
> > >
> > > But This returns always the complete dataframe, since the
> > > strsplit(dataframe[[Field]],",") is evaluated as one big list for the
> > > whole
> > > data frame rather than one list per row. How can I have this evaluated
> on
> > > a
> > > per row basis?
> > >
> > > After 1.5 h hitting head against wall - begging for insights ...
> > >
> > > Joh
> > >
> > > ______________________________________________
> > > R-help@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
> > > and provide commented, minimal, self-contained, reproducible code.
>
>


-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

        [[alternative HTML version deleted]]

______________________________________________
R-help@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
and provide commented, minimal, self-contained, reproducible code.

Reply via email to