There is a wrapper function and would like to use the function to keep deleting but I think only works for a record.
Here are the functions:
testFunc1:{
tab:([]a:`1`1`3`1`2;b:2 4 6 8 10);
tab2:update rowNumber:i from tab;
filter:select from tab2 where a = `1;
if [ ((count filter) > 0); tab2:raze .rm.tab[;tab2;filter] each til count filter];
tab:delete rowNumber from tab2;
tab
}
.rm.tab:{[x;tab;filter]
row:exec rowNumber[x] from filter;
if[(count tab) > 0; newTab: delete from tab where i = row];
:newTab
}
The idea is to have tab in testFunc1 and return it as .rm.tab is deleting the records one by one. I think there is a bug in .rm.tab, if only one record it works fine, but if there are 4 records in filter for looping, the output will return four times.
Not sure how I can fix the .rm.tab without using global variables?
Is this what you're looking for? I've removed the each from where .rm.tab is called & used /: (each-right) inside .rm.tab.
code
testFunc1:{
tab:([]a:`1`1`3`1`2;b:2 4 6 8 10);
tab2:update rowNumber:i from tab;
filter:select from tab2 where a=`1;
if[(count filter)>0;tab2:.rm.tab[;tab2;filter]til count filter];
:delete rowNumber from tab2;
}
.rm.tab:{[x;tab;filter]
row:exec rowNumber[x]from filter;
if[(count tab)>0;newTab:delete from tab where any i=/:row];
:newTab;
}
result
q)testFunc1[]
a b
----
3 6
2 10
Related
I want to use different constraints for din1 and din2. For example, it will execute din1<10 and din2<1000 first 10 times and then execute din1<5 and din2<10 for 10 times.
How can I do this?
this is one simple way to constrain list of structs:
keep insts.size() == 20;
keep for each in insts {
index < 10 => (it.din1 < 10 and it.din2 < 1000);
index >= 10 => (it.din1 < 5 and it.din2 < 10);
};
I have a table in MATLAB with attributes in the first three columns and data from the fourth column onwards. I was trying to sort the entire table based on the first three columns. However, one of the columns (Column C) contains months ('January', 'February' ...etc). The sortrows function would only let me choose 'ascend' or 'descend' but not a custom option to sort by month. Any help would be greatly appreciated. Below is the code I used.
sortrows(Table, {'Column A','Column B','Column C'} , {'ascend' , 'ascend' , '???' } )
As #AnonSubmitter85 suggested, the best thing you can do is to convert your month names to numeric values from 1 (January) to 12 (December) as follows:
c = {
7 1 'February';
1 0 'April';
2 1 'December';
2 1 'January';
5 1 'January';
};
t = cell2table(c,'VariableNames',{'ColumnA' 'ColumnB' 'ColumnC'});
t.ColumnC = month(datenum(t.ColumnC,'mmmm'));
This will facilitate the access to a standard sorting criterion for your ColumnC too (in this example, ascending):
t = sortrows(t,{'ColumnA' 'ColumnB' 'ColumnC'},{'ascend', 'ascend', 'ascend'});
If, for any reason that is unknown to us, you are forced to keep your months as literals, you can use a workaround that consists in sorting a clone of the table using the approach described above, and then applying to it the resulting indices:
c = {
7 1 'February';
1 0 'April';
2 1 'December';
2 1 'January';
5 1 'January';
};
t_original = cell2table(c,'VariableNames',{'ColumnA' 'ColumnB' 'ColumnC'});
t_clone = t_original;
t_clone.ColumnC = month(datenum(t_clone.ColumnC,'mmmm'));
[~,idx] = sortrows(t_clone,{'ColumnA' 'ColumnB' 'ColumnC'},{'ascend', 'ascend', 'ascend'});
t_original = t_original(idx,:);
I have a question about removing duplicates in a table (rexx language), I am on netphantom applications that are using the rexx language.
I need a sample on how to remove the duplicates in a table.
I do have a thoughts on how to do it though, like using two loops for these two tables which are A and B, but I am not familiar with this.
My situation is:
rc = PanlistInsertData('A',0,SAMPLE)
TABLE A (this table having duplicate data)
123
1
1234
12
123
1234
I need to filter out those duplicates data into TABLE B like this:
123
1234
1
12
You can use lookup stem variables to test if you have already found a value.
This should work (note I have not tested so there could be syntax errors)
no=0;
yes=1
lookup. = no /* initialize the stem to no, not strictly needed */
j=0
do i = 1 to in.0
v = in.i
if lookup.v <> yes then do
j = j + 1
out.j = v
lookup.v = yes
end
end
out.0 = j
You can eliminate the duplicates by :
If InStem first element, Move the element to OutStem Else check all the OutStem elements for the current InStem element
If element is found, Iterate to the next InStem element Else add InStem element to OutStem
Code Snippet :
/*Input Stem - InStem.
Output Stem - OutStem.
Array Counters - I, J, K */
J = 1
DO I = 1 TO InStem.0
IF I = 1 THEN
OutStem.I = InStem.I
ELSE
DO K = 1 TO J
IF (InStem.I ?= OutStem.K) & (K = J) THEN
DO
J = J + 1
OutStem.J = InStem.I
END
ELSE
DO
IF (InStem.I == OutStem.K) THEN
ITERATE I
END
END
END
OutStem.0 = J
Hope this helps.
I am using Gwt 2.5, i got this very simple code:
ButtonCell buttonCell=new ButtonCell();
CellList<String> cellList = new CellList<String>(buttonCell);
ListDataProvider<String> cellListDataProvider = new ListDataProvider<String>();
List<String> data = cellListDataProvider.getList();
for (int i = 1; i < 12; i++) {
data.add( String.valueOf(i));
}
cellListDataProvider.addDataDisplay(cellList);
SimplePager pager=new SimplePager();
pager.setDisplay(cellList);
pager.setPageSize(3);
Ok, now i ran, at the beginning it shows:
1
2
3
When i click 1 or 2 or 3 it doesn't jump to next page, that is good no problem
Then i click nextPage, it shows:
4
5
6
Now I click 4 then nothing happened but if i click 5 or 6 then it automatically jumps to the next page to display though I did not click the nextpgae in pager:
7
8
9
So what is wrong with that?
If i change ButtonCell to TextCell, then there is no problem at all.
The issue is due to DefaultKeyboardSelectionHandler.Check execution of that handler.
You can fix your issue by disabling KeyboardSelectionPolicy of your CellList
cellList.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED);
indexpath.row for array b.tag
0 Date1 0
1 india 1
2 pakistan 2
3 Date2 3
4 Zimbabwe 3
5 England 4
6 Date3 6
7 Australia 5
8 Westindes 6
9 Date3 9
10 Shrilanka 7
11 southAfrica 8
Here, indexpath.row for array is my Array. Now when i click on b.tag=3 then I want to display Array index 4th value i.e Zimbabwe and not the Date2 which is on array index 3. Similarly, for b.tag=6 and b.tag=9. For that following is the code that i have written.
please take a look...
if (b.tag!=[arr objectAtIndex:path])
{
NSLog(#"Team name %#",[arr objectAtIndex:b.tag]);
}
From the above code my first record result is coming right i.e of b.tag=1 and b.tag=2,but not for others because my Array index and b.tag are different. So please help me out of this.
Any help will be appreciated.
Thanks in Advance.
Why not change the contents of the array to better reflect your button tags?
It seems you have two different data types represented by one array, split them out:
NSArray *teamArray = [NSArray arrayWithObjects:#"India", #"Pakistan", #"Zimbabwe", #"England", #"Australia", #"WestIndies", #"Shrilanka", #"SouthAfrica", nil];
NSLog(#"Team name %#",[teamArray objectAtIndex:b.tag]);
It seems you have passed a same tag for two instance of buttons why don't you just set the tag like this b.tag = indexPath.row?.
UPDATE
use this code -
NSInteger index = b.tag;
if(b.tag != 0 && b.tag %3 == 0){
index = index+1;
}
NSLog(#"Team name %#",[arr objectAtIndex:index]);
Update
I have tested this code and it's showing index = 4 when index was 4 it's not increasing the index value
self.view.tag = 4;
NSInteger index = self.view.tag;
if(index%3 == 0 && index != 0)
{
index = index+1;
NSLog(#"Index Value Is %d",index);
}
NSLog(#"Index Value Is %d",index);