[c785b5]: @dataframe / fold.m Maximize Restore History

Download this file

fold.m    96 lines (83 with data), 2.9 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
function resu = fold(df, dim, indr, indc)
%# function resu = subasgn(df, S, RHS)
%# The purpose is to fold a dataframe. Part from (1:indr-1) doesn't
%# move, then content starting at indr is moved into the second,
%# third, ... sheet. To be moved, there must be equality of rownames,
%# if any, and of fields contained in indc.
%% Copyright (C) 2009-2010 Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
%%
%% This file is part of Octave.
%%
%% Octave is free software; you can redistribute it and/or
%% modify it under the terms of the GNU General Public
%% License as published by the Free Software Foundation;
%% either version 2, or (at your option) any later version.
%%
%% Octave is distributed in the hope that it will be useful,
%% but WITHOUT ANY WARRANTY; without even the implied
%% warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
%% PURPOSE. See the GNU General Public License for more
%% details.
%%
%% You should have received a copy of the GNU General Public
%% License along with Octave; see the file COPYING. If not,
%% write to the Free Software Foundation, 59 Temple Place -
%% Suite 330, Boston, MA 02111-1307, USA.
%#
%# $Id: fold.m 1016 2010-07-30 13:49:35Z dupuis $
%#
switch dim
case 1
[indr, nrow] = df_name2idx(df._name{1}, indr, df._cnt(1), 'row');
[indc, ncol] = df_name2idx(df._name{2}, indc, df._cnt(2), 'column');
if indr(1) > 1,
slice_size = indr(1) - 1;
%# we can't use directly resu = df(1:slice_size, :, :)
S.type = '()';
S.subs = { 1:slice_size, ':', ':', 'dataframe'};
resu = subsref(df, S);
%# how many columns for each slice
targets = cellfun('size', df._data, 2);
%# a test function to determine if the location is free
for indj = 1:df._cnt(2),
if any(indj == indc),
continue;
endif
switch df._type{indj}
case { 'char' }
testfunc{indj} = @(x, indr, indc) ...
!isna(x{indr, indc});
otherwise
testfunc{indj} = @(x, indr, indc) ...
!isna(x(indr, indc));
endswitch
endfor
for indi = indr,
%# where does this line go ?
where = find(df._data{indc}(1:slice_size, 1) ...
== df._data{indc}(indi, 1));
if !isempty(where),
%# transfering one line -- loop over columns
for indj = 1:df._cnt(2),
if any(indj == indc),
continue;
endif
if testfunc{indj}(resu._data{indj}, where, targets(indj))
%# add one more sheet
resu = df_pad(resu, 3, 1, indj);
targets(indj) = targets(indj) + 1;
endif
%# transfer field
resu._data{indj}(where, targets(indj)) = ...
df._data{indj}(indi, 1);
endfor
%# update row index
resu._ridx(where, max(targets)) = df._ridx(indi);
else
disp('line 65: FIXME'); keyboard;
endif
endfor
else
disp('line 70: FIXME '); keyboard
endif
endswitch