Here is one way to do this. First define the entries of the entire table:
\newcommand*{\MyTabularEntries}{%
Row & dataset & some numbers \\,
\unexpanded{\cmidrule(r){1-1}\cmidrule(lr){2-2}\cmidrule(l){3-3}},
3 & A & 10 \\,
4 & B & 11 \\,
5 & C & 12 \\,
\unexpanded{\cmidrule{1-3}},
7 & D & 48 \\,
8 & E & 144 \\,
}%
and then build the table with only the dried rows by invoking
\InsertTable[<csv list of rows>]{<title>}{\MyTabularEntries}

Notes:
- I added a row number to make it easier to see that this solution is working correctly. The header and
cmidrule
are counted.
- I also used the
booktabs
package as that produces better tables.
References
Code:
\documentclass{article}
\usepackage{etoolbox}
\usepackage{booktabs}
\usepackage{xparse}
\usepackage{tikz}
\newcommand*{\MyTempTableTokens}{}%
\makeatletter
\newtoks\@tabtoks
%%% assignments to \@tabtoks must be global, because they are done in \foreach
\newcommand\AddTableTokens[1]{\global\@tabtoks\expandafter{\the\@tabtoks#1}}
\newcommand\eAddTableTokens[1]{%
\protected@edef\MyTempTableTokens{#1}%
\expandafter\AddTableTokens\expandafter{\MyTempTableTokens}%
}
%%% variable should always be operated on always locally or always globally
\newcommand*\ResetTableTokens{\global\@tabtoks{}}
\newcommand*\PrintTableTokens{\the\@tabtoks}
%% \processlist is based on a contribution by Hood Chatham
\newcount\tempcount
\newcommand*{\MacroToExecute}{}%
\def\processlist#1#2{\def\MacroToExecute{#1}\processlist@#2,\@nil}
\def\processlist@#1,{%
\in@-{#1}%
\ifin@
\processrange#1\@nil
\else
\MacroToExecute{Row #1}{}%
\fi
\@ifnextchar\@nil{\@gobble}{\processlist@}%
}
\def\processrange#1-#2\@nil{%
\tempcount=#1\relax
\loop
\MacroToExecute{Row \the\tempcount}{}%
\advance\tempcount1\relax
\unless\ifnum\tempcount>#2\repeat
}
\makeatother
\newcommand*{\MyTabularEntries}{%
Row & dataset & some numbers \\,
\unexpanded{\cmidrule(r){1-1}\cmidrule(lr){2-2}\cmidrule(l){3-3}},
3 & A & 10 \\,
4 & B & 11 \\,
5 & C & 12 \\,
\unexpanded{\cmidrule{1-3}},
7 & D & 48 \\,
8 & E & 144 \\,
}%
\newcounter{RowNumber}
\NewDocumentCommand{\InsertTable}{%
O{1-10}% #1 = range of lines to print, defaults to all lines from 1-99
m% #2 = table title
m% #3 = list of entries (terminated by comma).
}{%
\processlist{\csdef}{#1}%
\ResetTableTokens%
\setcounter{RowNumber}{0}%
\foreach \Entry in #3 {%
\stepcounter{RowNumber}%
\ifcsdef{Row \arabic{RowNumber}}{%
\eAddTableTokens{\Entry}%
}{%
%% This row number was not requested so skip it
}%
}%
\begin{tabular}{lll}
\toprule
\multicolumn{3}{c}{#2} \\
\PrintTableTokens
\bottomrule
\end{tabular}%
% Clear the desired rows list
\processlist{\csundef}{#1}%
}
\begin{document}
\InsertTable{All Rows}{\MyTabularEntries}%
\par\medskip
\InsertTable[1-5]{Rows 1-5}{\MyTabularEntries}%
\par\medskip
\InsertTable[1,2,4,6-10]{Rows 1,2,4,6-10}{\MyTabularEntries}%
\end{document}