1 function resu = summary(df)
2 %# function resu = summary(df)
3 %# This function prints a nice summary of a dataframe, on a
4 %# colum-by-column basis. For continuous varaibles, returns basic
5 %# statistics; for discrete one (char, factors, ...), returns the
6 %# occurence count for each element.
8 %% Copyright (C) 2009-2012 Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
10 %% This file is part of Octave.
12 %% Octave is free software; you can redistribute it and/or
13 %% modify it under the terms of the GNU General Public
14 %% License as published by the Free Software Foundation;
15 %% either version 2, or (at your option) any later version.
17 %% Octave is distributed in the hope that it will be useful,
18 %% but WITHOUT ANY WARRANTY; without even the implied
19 %% warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 %% PURPOSE. See the GNU General Public License for more
23 %% You should have received a copy of the GNU General Public
24 %% License along with Octave; see the file COPYING. If not,
25 %% write to the Free Software Foundation, 51 Franklin Street -
26 %% Fifth Floor, Boston, MA 02110-1301, USA.
29 %# $Id: summary.m 9585 2012-02-05 15:32:46Z cdemills $
32 dummy = df._type; resu = [];
34 for indi = 1:length(dummy),
36 case {'char' 'factor'}
37 [sval, sidxi, sidxj] = unique(df._data{:, indi});
38 %# compute their occurences
39 sidxj = hist(sidxj, min(sidxj):max(sidxj));
40 %# generate a column with unique values
41 resuR = strjust(char(regexp(disp(sval), '\S.*', 'match', ...
42 'dotexceptnewline')), 'right');
43 resuR = horzcat(resuR, repmat(':', size(resuR, 1), 1),
44 strjust(char(regexp(disp(sidxj.'), '\b.*', 'match', ...
45 'dotexceptnewline')), ...
47 %# now put the name above all
48 resuR = strjust([deblank(df._name{1, 2}(indi, :)); resuR], 'right');
49 resuR = horzcat(resuR, repmat(' ', size(resuR, 1), 1));
50 resu = horzcat_pad(resu, resuR);
53 s = statistics(df._data{:, indi});
55 %# generate a column with name and fields name
56 resuR = strjust([deblank(df._name{1, 2}{indi, :});
59 "3rd Qu.:"; "Max. :"], 'right');
60 %# generate a column with a blank line and the values
61 resuR = horzcat(resuR, repmat(' ', size(resuR, 1), 1),
62 strjust(char(' ', regexp(disp(s), '\S.*', 'match', ...
63 'dotexceptnewline')), 'right'),...
64 repmat(' ', size(resuR, 1), 1));
65 resu = horzcat_pad(resu, resuR);
73 function resu = horzcat_pad(A, B)
74 %# small auxiliary function to cat horizontally tables of different height
75 dx = size(A, 1) - size(B, 1);
79 A = strvcat(A, repmat(' ', -dx, size(A, 2)));
81 B = strvcat(B, repmat(' ', dx, size(B, 2)));