title: R OOP CODE that return results from data set
body: <p>I am trying to work on a OOP code in R. The dataset I am using is something like bellow:</p>
  
  <pre><code>ID VISIT  ROOM TYPE  VALUE
  3   0     bedroom     20
  3   1     Office      11
  3   1     bedroom     5
  </code></pre>
  
  <p>I need to write a code using OOP (S3, S4, or RC) in R creating a function 'subject' that would work on the following situations bellow:</p>
  
  <pre><code>##check if subject exists
  out &lt;- subject(x, 3)
  print(out)
  Subject ID: 3 
  
  ##summary by visit, room type on subject ID
   out &lt;- subject(x, 3) %&gt;% summary
   print(out)
  ID:3    
  visit bedroom  office
    0    20       NA
    1    5        11
  
  ## Show a summary of values
  out &lt;- subject(x, 3) %&gt;% visit(0) %&gt;% room("bedroom") %&gt;% summary
  print(out)
  ID: 3 
     Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
      3.0    27.0    40.0    20.8    70.0   200.0 
  </code></pre>
  
  <p>I am not used to write in OOP so it is rather difficult for me. Any advice on how to start or example would be great.</p>
  
  <p>Appreciate any help</p>
  
  <p>Tks</p>