Skip to content

R-help: grep in for loop using index - doesn't work

1 message · Mohan Singh

#
Thanks Phil.  

That worked. 

The apply(..) commands gives me a single 1/0 output for each column which
has the query item or not. 

But I am looking to find the index i from the loop to extract that
particular value for plotting

I'll try to improve the data.frame part; I was not able to access the rows
with data (just started R), so I created individual frames for data

Cheers
Mohan


-----Original Message-----
From: Phil Spector [mailto:spector at stat.berkeley.edu] 
Sent: Wednesday, March 11, 2009 10:46 PM
To: Mohan Singh
Subject: Re: [R] R-help: grep in for loop using index - doesn't work

Mohan -
    "i" is the literal character i.  i is the variable called
i.  In this case, you want the variable, i.e. i:

   p1 <- grep("QueryItem",c1data[i,],value=FALSE,fixed=FALSE)

I might also mention that creating a separate data frame for each
column of your data is not really a good idea.  I believe that you're
looking for a solution like

     apply(data,2,grep,"Query Item")

but it's hard to tell.  You might want to run that command 
and see if what you want is in the output.

                                        - Phil Spector
 					 Statistical Computing Facility
 					 Department of Statistics
 					 UC Berkeley
 					 spector at stat.berkeley.edu
On Wed, 11 Mar 2009, Mohan Singh wrote:

            
http://www.R-project.org/posting-guide.html