2

I'm trying to subset, in a big file, all the words that DO NOT end with "_at".

For example: the file "myfile" is a data.frame composed as follow (specifically I have a file with 50 columns and 1000 rows):

myfile <- read.table( text = '"G1"            "G2"  
    SEP11          ABCC1   
    205772_s_at    FMO2   
    214223_at      ADAM19     
    ANK2           215742_at 
    COPS4          BIK 
    214808_at      DCP1A
    ACE            ALG3
    BAD            215369_at
    EMP3           215385_at
    CARD8          217579_x_at
', header = TRUE, stringsAsFactors = FALSE)

I would like the following output:

  "G1"           "G2"  
 SEP11          ABCC1  
 ANK2           FMO2  
 COPS4          ADAM19     
 ACE            BIK   
 BAD            DCP1A
 EMP3           ALG3 
 CARD8

I used the following string but it doesn't work probably because I'm doing something wrong:

sub <- myfile[-grep("\\_at", names(myfile)), ]

Can anyone help me?

oguz ismail
  • 1
  • 16
  • 47
  • 69
Bfu38
  • 1,081
  • 1
  • 8
  • 17
  • 2
    Please make your example reproducible: http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example. – Paul Hiemstra Nov 13 '12 at 09:44
  • 1
    Your PS does not change whether we can reproduce your example or not. We don't need to see your full file, for the purpose of asking the question, `myfile` does not need to be big. Just follow the link Paul posted and create something we can reproduce. Doing this will improve the usefulness of your question and your chances to get a useful answer. – Romain Francois Nov 13 '12 at 10:11

1 Answers1

6

The following code will give you a list. Each element of the list being a subset of one of your column filtered by the regular expression _at$. See ?grep .

lapply( myfile, 
   function(column) grep( "_at$", column, invert = TRUE, value = TRUE )
)
Romain Francois
  • 17,432
  • 3
  • 51
  • 77