\begin{table}
  \centering
  \begin{tabular}{|c|p{5cm}|p{5cm}|}
  \hline
  Concept & SQL & \R (\cmd{dplyr}) \\
  \hline
  Filter by rows \& columns 
    & \cmd{SELECT col1, col2 FROM $a$ WHERE col3 = 'x'} 
    & \cmd{select(filter($a$, col3 == "x"), col1, col2)} \\
  \hline
  Aggregate by rows 
    & \cmd{SELECT id, sum(col1) as total FROM $a$ GROUP BY id} 
    & \cmd{summarise(group\_by($a$, id), total = sum(col1))} \\
%    & \cmd{ddply($a$[,c(id, col1)], $\sim$ id, sum)} \\
  \hline
  Combine two tables 
    & \cmd{SELECT * FROM $a$ JOIN $b$ ON a.id = b.id} 
    & \cmd{inner\_join(x=$a$, y=$b$, by="id"))} \\
  \hline
  \end{tabular}
  \caption{Conceptually analogous SQL and \R commands. Suppose $a$ and $b$ are SQL tables or \R \cmd{data.frame}s}
  \label{tab:sql-r}
\end{table}
Concept SQL R (dplyr)
Filter by rows & columns SELECT col1, col2 FROM a
WHERE col3 = ’x’ select(filter(a, col3 ==
"x"), col1, col2)
Aggregate by rows SELECT id, sum(col1) as
total FROM a GROUP BY id summarise(group by(a, id),
total = sum(col1))
Combine two tables SELECT * FROM a JOIN b ON
a.id = b.id inner join(x=a, y=b,
by="id"))