title: selecting rows of which the value of the variable is equal to certain vector
body: <p>I have a longitudinal data called <code>df</code> for more than 1000 people that looks like the following:</p>
  
  <pre><code>id  year    name    status  
  1   1984    James   4   
  1   1985    James   1   
  2   1983    John    2   
  2   1984    John    1   
  3   1980    Amy     2   
  3   1981    Amy     2   
  4   1930    Jane    4   
  4   1931    Jane    5   
  </code></pre>
  
  <p>I'm trying to subset the data by certain <code>id</code>. For instance, I have a vector <code>dd</code> that consists of <code>id</code>s that I would like to subset:</p>
  
  <pre><code>dd&lt;-c(1,3)
  </code></pre>
  
  <p>I've tried the following but it did not work, for instance:</p>
  
  <pre><code>subset&lt;-subset(df, subset(df$id==dd))
  </code></pre>
  
  <p>or</p>
  
  <pre><code>subset&lt;-subset(df, subset(unique(df$id))==dd))
  </code></pre>
  
  <p>or</p>
  
  <pre><code>subset&lt;-df[which(unique(df$id)==dd),]
  </code></pre>
  
  <p>or I tried a for-loop</p>
  
  <pre><code>for (i in 1:2){
    subset&lt;-subset(df, subset=(unique(df$id)==dd[i]))
  }
  </code></pre>
  
  <p>Would there be a way to only select the rows with the <code>id</code>s that match the numbers in in the vector <code>dd</code>?</p>