| 1 |
% This file is embedded in datatool-user.pdf version 3.4.3 2025-12-04 |
| 2 |
% Example 68 Row aggregate actions |
| 3 |
% Label: "ex:rowaggregates" |
| 4 |
% arara: pdflatex |
| 5 |
% arara: pdfcrop |
| 6 |
\documentclass[12pt]{article} |
| 7 |
\pagestyle{empty} |
| 8 |
% sample CSV file: |
| 9 |
\begin{filecontents}[noheader,overwrite]{studentmarks.csv} |
| 10 |
Surname,Forename,StudentNo,Assign1,Assign2,Assign3 |
| 11 |
"Smith, Jr",John,102689,68,57,72 |
| 12 |
"Brown",Jane,102647,75,84,80 |
| 13 |
"Brown",Jane,102646,64,92,79 |
| 14 |
"Brown",Andy,103569,42,52,54 |
| 15 |
"Adams",Zoƫ,105987,52,48,57 |
| 16 |
"Brady",Roger,106872,68,60,62 |
| 17 |
"Verdon",Clare,104356,45,50,48 |
| 18 |
\end{filecontents} |
| 19 |
|
| 20 |
|
| 21 |
\usepackage{datatool} |
| 22 |
|
| 23 |
|
| 24 |
% Load data from studentmarks.csv file: |
| 25 |
\DTLsetup{store-datum,default-name=marks} |
| 26 |
\DTLread{studentmarks.csv} |
| 27 |
\begin{document} |
| 28 |
Map data: |
| 29 |
|
| 30 |
\DTLmapdata[name=marks]{ |
| 31 |
\DTLmapget{key=Forename} \DTLmapget{key=Surname} average marks: |
| 32 |
\DTLaction[ |
| 33 |
columns={4-}, |
| 34 |
options={mean} |
| 35 |
]{row aggregate} |
| 36 |
\DTLuse{mean}. |
| 37 |
|
| 38 |
} |
| 39 |
|
| 40 |
For each: |
| 41 |
|
| 42 |
\DTLforeach{marks}{\Forename=Forename,\Surname=Surname}{ |
| 43 |
\Forename\ \Surname\ |
| 44 |
average mark: |
| 45 |
\DTLaction[ |
| 46 |
columns={4-}, |
| 47 |
options={mean} |
| 48 |
]{current row aggregate} |
| 49 |
\DTLuse{mean}. |
| 50 |
|
| 51 |
} |
| 52 |
|
| 53 |
Row selection: |
| 54 |
|
| 55 |
\dtlgetrowforvalue{marks}{\dtlcolumnindex{marks}{StudentNo}}{105987} |
| 56 |
Student 105987 average mark: |
| 57 |
\DTLaction[ |
| 58 |
columns={4-}, |
| 59 |
options={mean} |
| 60 |
]{current row aggregate} |
| 61 |
\DTLuse{mean}. |
| 62 |
\end{document} |