title: Creating indicator column based on conditional categorizing of rows in R
body: <p>I have a dataset like this:</p>
  
  <pre><code>user.id  user_type
  3          old
  3          old
  4          new
  5          new
  5          new
  6          old
  </code></pre>
  
  <p>I want to create new column that would indicate the first time user_type is 'new' for each user_id.</p>
  
  <p>Output should look like this:</p>
  
  <pre><code>user.id  user_type  indicator
  3          old         2
  3          old         2
  4          new         1
  5          new         1
  5          new         2
  6          old         2
  </code></pre>
  
  <p>I used transform function but it is not working, my code:</p>
  
  <pre><code>input &lt;- transform(input, user =
  ifelse(head(user_type) == "NEW", 1, 2))
  </code></pre>