-4

Let me improve and be more specific:

df <- read.table(header=T, stringsAsFactors=FALSE, text='  
AccNumb     Reference   Amount  
101a         AX01        500  
101a         AX02        499  
102b         AX01        500  
101a         AX03        322  
101a         AX03        300        
')  

I want subset data, where AccNumb is different and reference is equal.

In this example this is:

101a         AX01        500   
102b         AX01        500        

How I can do this? Thanks!

====Original

For example, we have data.table like this:

AccNumb,Reference, Amount  
001,REF1,500  
002,REF1,500  
001,REF2,455  
001,REF3,222  

I want data with AccNumb<>AccNumb and Reference==Reference

How I can do that? Thanks!

Rich Scriven
  • 97,041
  • 11
  • 181
  • 245
  • 1
    Please read about how to supply [a reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) and clarify your question. – Thomas Nov 25 '14 at 20:00

1 Answers1

1
dt <- dt[dt$AccNumb == "value_for_AccNumb" & dt$Reference == "value_for_reference",]

subset() is a convenience function - a really convenient one, but still a convenience function. You can perform subsets without it.

Oliver Keyes
  • 3,294
  • 2
  • 14
  • 23
  • 3
    .. in data.tables, you don't need to reference `dt$..` when accessing column names – talat Nov 25 '14 at 20:06
  • Fair! I tend to use the syntax anyway because it's accidentally-made-a-df-instead-proof. – Oliver Keyes Nov 25 '14 at 20:23
  • 2
    Hm, I'm not a data.table user, but I think this wouldn't be considered good data.table practice .. – talat Nov 25 '14 at 20:25
  • 1
    Probably, but it works. Accidentally forgetting it with a data.frame doesn't. My coding style is oriented around assuming that Future Oliver is a forgetful sod ;). – Oliver Keyes Nov 25 '14 at 20:26