text: user1513: I have a big df like following (pseudo) df and I want to retrieve values in different col. according to the rows in the first col.
  A B C D
  a 1 1 1
  a 2 3 1 
  a 3 3 3 
  a 4 5 6 
  b 5 6 5 
  b 7 6 5 
  c 7 6 5 
  c 5 4 3 
  c 5 5 4 
  
  I want to retrieve the values in col. B, C, and D according to the rows in col A and perform further analysis of them. For example, multiply the values in col B and C for all the rows of "a" in col A. Can someone suggest a commend for such a naive question. Thanks. 
  
  user776: Here's an approach that uses native R, using the vectorized (fast) family of apply() functions. 
  > df2 <- df[df$A == 'a', which(names(df) %in% c("B","C"))]
  > apply(df2, 1, prod)
  
  Use apply/lapply/mapply/etc. where you can in place of alternatives, where you don't know their run characteristics.
  Here's a more concrete example:
  > df
    A B C D
  1 a 1 1 1
  2 a 2 3 1
  3 a 3 3 3
  4 a 4 5 6
  5 b 5 6 5
  ...
  > df2 <- df[df$A == 'a', which(names(df) %in% c("B","C"))]
  > df2
    B C
  1 1 1
  2 2 3
  3 3 3
  4 4 5
  > apply(df2, 1, prod)
   1  2  3  4 
   1  6  9 20
  
  Edit: If you need to do this on each unique value of df$A, you can nest apply calls to make this scale:
  > perA.list <- apply(data.frame(unique(df$A)), 1, function(x) apply(df[df$A == x, which(names(df) %in% c("B","C"))], 1, prod))
  > perA.list
  [[1]]
   1  2  3  4 
   1  6  9 20
  
  [[2]]
   5  6
  30 35
  
  [[3]]
   7  8  9
  35 20 25
  
  Each index in this list correspondents to the index of the value from unique(df$A), i.e. a, b, and c.
  If you don't want to do this for all unique values in df$A, but for some specific element in df$A, then you would just need to write a function. 95% of the code is in this answer to write such a function, so I'll leave that as a homework exercise for you to implement.
  
original_text: 1513: <p>I have a big df like following (pseudo) df and I want to retrieve values in different col. according to the rows in the first col.</p>
  
  <pre><code>A B C D
  a 1 1 1
  a 2 3 1 
  a 3 3 3 
  a 4 5 6 
  b 5 6 5 
  b 7 6 5 
  c 7 6 5 
  c 5 4 3 
  c 5 5 4 
  </code></pre>
  
  <p>I want to retrieve the values in col. B, C, and D according to the rows in col A and perform further analysis of them. For example, multiply the values in col B and C for all the rows of "a" in col A. Can someone suggest a commend for such a naive question. Thanks. </p>
   776: <p>Here's an approach that uses native R, using the vectorized (fast) family of <code>apply()</code> functions. </p>
  
  <pre><code>&gt; df2 &lt;- df[df$A == 'a', which(names(df) %in% c("B","C"))]
  &gt; apply(df2, 1, prod)
  </code></pre>
  
  <p>Use apply/lapply/mapply/etc. where you can in place of alternatives, where you don't know their run characteristics.</p>
  
  <p>Here's a more concrete example:</p>
  
  <pre><code>&gt; df
    A B C D
  1 a 1 1 1
  2 a 2 3 1
  3 a 3 3 3
  4 a 4 5 6
  5 b 5 6 5
  ...
  &gt; df2 &lt;- df[df$A == 'a', which(names(df) %in% c("B","C"))]
  &gt; df2
    B C
  1 1 1
  2 2 3
  3 3 3
  4 4 5
  &gt; apply(df2, 1, prod)
   1  2  3  4 
   1  6  9 20
  </code></pre>
  
  <p><strong>Edit</strong>: If you need to do this on each unique value of <code>df$A</code>, you can nest <code>apply</code> calls to make this scale:</p>
  
  <pre><code>&gt; perA.list &lt;- apply(data.frame(unique(df$A)), 1, function(x) apply(df[df$A == x, which(names(df) %in% c("B","C"))], 1, prod))
  &gt; perA.list
  [[1]]
   1  2  3  4 
   1  6  9 20
  
  [[2]]
   5  6
  30 35
  
  [[3]]
   7  8  9
  35 20 25
  </code></pre>
  
  <p>Each index in this list correspondents to the index of the value from <code>unique(df$A)</code>, i.e. <code>a</code>, <code>b</code>, and <code>c</code>.</p>
  
  <p>If you don't want to do this for all unique values in <code>df$A</code>, but for some specific element in <code>df$A</code>, then you would just need to write a function. 95% of the code is in this answer to write such a function, so I'll leave that as a homework exercise for you to implement.</p>
  