title: Get row index for queried element in R
body: <p>I want to get the position of an item in my vector, turns out to be difficult:</p>
  
  <p>My data table holds 5 columns</p>
  
  <pre><code>                   ts Q_m3s Baseflow_r1 Baseflow_r2 leer_1 year
   1: 1965-01-01 00:00:00   156         156         150      0   65
   2: 1965-01-01 01:00:00   155         155         150      0   65
   3: 1965-01-01 02:00:00   154         154         150      0   65
   4: 1965-01-01 03:00:00   154         154         150      0   65
   5: 1965-01-01 04:00:00   153         153         150      0   65
   6: 1965-01-01 05:00:00   152         152         150      0   65
  </code></pre>
  
  <p>The first column ts is converted to a POSIXct element</p>
  
  <pre><code>dt &lt;- data.table(data) # convert to data table 
  dt[,ts:=as.POSIXct(ts, format="%m%d%Y %H:%M")] # convert to POSIXct
  # get year
  dt[, ':='(year=as.POSIXlt(ts)$year)]
  </code></pre>
  
  <p>I now want to get the POSITION of the maximum value in a given year.</p>
  
  <p>The expression <code>max(dt$Q_m3s[dt[,year==105]])</code> yields the maximum per selected year, but I have no idea how to get the position, i.e. the row index.</p>
  
  <p>Any help appreciated!
  Best 
  Jochen</p>