title: How to convert Stata marksample in R language?
body: <p>I am new to Stata, but I need to think about converting  a piece of Stata code to R for later convenience. </p>
  
  <p>One piece of Stata code is following</p>
  
  <pre><code>marksample touse
  quietly: keep if `touse'
  </code></pre>
  
  <p>From help(marksample) in Stata, I think marksample is going to give Index to each row of the data sets and mark each row as 1 when it is qualified, or 0 otherwise. There are several rules applied.</p>
  
  <p><em>1.  The marker variable is set to 0 in observations for which weight is 0 (but see option zeroweight).
  2.  The appropriate error message is issued, and everything stops if weight is invalid (such as being less than 0 in some observation or being a
          noninteger for frequency weights).
  3.  The marker variable is set to 0 in observations for which the if exp is not satisfied.
  4.  The marker variable is set to 0 in observations outside the in range.
  5.  The marker variable is set to 0 in observations for which any of the numeric variables in varlist contain a numeric missing value.
  6.  The marker variable is set to 0 in all observations if any of the variables in varlist are strings; see option strok for an exception.
  7.  The marker variable is set to 1 in the remaining observations.
  Using the name touse is a convention, not a rule, but it is recommended for consistency between programs.</em></p>
  
  <p>May I know if there is anyway in R to convert this part of code easily (packages or functions)? Or I have to create the rules in R manually by myself?</p>