Sorry about that. I will try to reformat my question.

I have a dataset with format like:
----------------------------------
> head(data)
           V1     V2         V3           V4       V5  V6       V7           V8
1 ref_gene_id ref_id class_code cuff_gene_id  cuff_id FMI     FPKM FPKM_conf_lo
2           -      -          u       C.3 C.3.1 100 1.000000     0.000000
3           -      -          u       C.2 C.2.1 100 1.000000     0.000000
4           -      -          u       C.4 C.4.1 100 1.000000     0.000000
5           -      -          u       C.1 C.1.1 100 1.000000     0.000000
6           -      -          u       C.5 C.5.1 100 1.000000     0.000000
            V9      V10 V11          V12           V13
1 FPKM_conf_hi      cov len major_iso_id ref_match_len
2     0.000000 0.056682  96     C.3.1             -
3     0.000000 0.058453  99     C.2.1             -
4     0.000000 0.059634 101     C.4.1             -
5     0.000000 0.059634 101     C.7.1             -
6     0.000000 0.059634 101     C.5.1             -
---------------------
here column5 has extra ".1" compared with column4, and column12 might be 
different from column5 with similar format, for example row 5; but most of them 
(column5 and column12) are the same (like the rest of the rows) . I am trying 
to find the different ones by using "grep"

this data has a dimension of  52086  by 13

so my ran the following code:
------------
> dim(data)
[1] 52086    13
>  if(grep(data[3,4],data[3,12])==1) print("Y")
[1] "Y"
> for(i in 1:52086){if(grep(data[i,4],data[i,12])==1) print ("Y")}
Error in if (grep(data[i, 4], data[i, 12]) == 1) print("Y") :
  argument is of length zero

-----------

here I tested the grep command first and it looks ok. However, when I put it in 
for loop, error message came: 
argument is of length zero

Could you please help me figure out what happened here?

Thanks a lot for your help.



________________________________
 From: Jeff Newmiller <jdnew...@dcn.davis.ca.us>

ect.org> 
Sent: Friday, September 13, 2013 10:36 PM
Subject: Re: [R] problem with grep under loop


Please read the Posting Guide before you post again, and study how to make a 
reproducible example of your problem [1], and change the settings on your mail 
program to send plain text. I, for one, am not psychic, so need things spelled 
out clearly.

[1] 
http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example

---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnew...@dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
---------------------------------------------------------------------------
Sent from my phone. Please excuse my brevity.


[[elided Yahoo spam]]
>
>I then first test my data:
>
>> dim(data)
>[1] 52086    13
>>  if(grep(data[3,4],data[3,12])==1) print("Y")
>[1] "Y"
>> for(i in 1:52086){if(grep(data[i,4],data[i,12])==1) print ("Y")}
>Error in if (grep(data[i, 4], data[i, 12]) == 1) print("Y") :
>  argument is of length zero
>
>
>What is this new error message? "argument is of length zero"
>
>Here is my data format:
>>head(data)
>
>           V1     V2         V3           V4       V5  V6      
>V7           V8
>1 ref_gene_id ref_id class_code cuff_gene_id  cuff_id FMI     FPKM
>FPKM_conf_lo
>2           -      -          u       C.3 C.3.1 100 1.000000    
>0.000000
>3           -      -          u       C.2 C.2.1 100 1.000000    
>0.000000
>4           -      -          u       C.4 C.4.1 100 1.000000    
>0.000000
>5           -      -          u       C.1 C.1.1 100 1.000000    
>0.000000
>6           -      -          u       C.5 C.5.1 100 1.000000    
>0.000000
>            V9      V10 V11          V12           V13
>1 FPKM_conf_hi      cov len major_iso_id ref_match_len
>2     0.000000 0.056682  96     C.3.1             -
>3     0.000000 0.058453  99     C.2.1             -
>4     0.000000 0.059634 101     C.4.1             -
>5     0.000000 0.059634 101     C.2.1             -
>6     0.000000 0.059634 101     C.5.1             -
>
>
>________________________________
> From: Jeff Newmiller <jdnew...@dcn.davis.ca.us>

>"r-help@r-project.org" <r-help@r-project.org> 
>Sent: Friday, September 13, 2013 9:21 PM
>Subject: Re: [R] problem with grep under loop
> 
>
>This is because you are not printing it (with the print or cat
>functions). Keep in mind that the visible result you get from calling a
>function or evaluating a variable interactively comes from the
>interactive R command line, not from R itself. Once you put such an
>expression inside a function (such as the "for" function) it is no
>longer directly being invoked by the command interpreter.
>
>You might want to read [1] and [2] (which says don't post using HTML).
>
>[1]
>http://stackoverflow.com/questions/4716152/why-do-r-objects-not-print-in-a-function-or-a-for-loop
>[2] http://www.R-project.org/posting-guide.html
>---------------------------------------------------------------------------
>Jeff Newmiller                        The     .....       .....  Go
>Live...
>DCN:<jdnew...@dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live
>Go...
>                                      Live:   OO#.. Dead: OO#.. 
>Playing
>Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
>/Software/Embedded Controllers)               .OO#.       .OO#. 
>rocks...1k
>---------------------------------------------------------------------------
>
>Sent from my phone. Please excuse my brevity.
>

>>
>>
>>I am just testing the possibility of using grep under for loop:
>>
>>>for(i in 1:10){grep("a",letters)}
>>
>>
>>nothing came out;
>>
>>when I ran: 
>>
>>
>>>grep("a",letters), 
>>
>>
>>I got "1"
>>
>>so in my for loop, I expected to see ten "1"s, but I did not.
>>
>>Could anybody help me to figure out why? Thanks a lot for your help.
>>
>>Capricy
>>    [[alternative HTML version deleted]]
>>
>>______________________________________________
>>R-help@r-project.org 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.
        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org 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