I have like this table with numbers -1, 0 and 1.
Innovation,Licensing,Marketing,Portfolio,Purchase,Quality,Support
1,1,0,1,1,1,1
0,-1,-1,-1,0,1,1
1,1,1,1,1,1,1
-1,0,0,1,-1,1,0
...
Each row is an answer of customers where 1 - is recommend, -1 - not recommend and 0 - doesn't matter.
I need to separate each row on the pairs, where 1 - best answer and -1 - worst answer (1 best 0, 0 best -1) like in table below.
Algorithm:
In the 1st row need to compare 1st number with 2nd. If numbers the same, need to compare with next number - 1st with 3rd.
Source
1,1,0,1,1,1,1
If 1st better 3rd, then write a new row to the result table where 1st number will be '1', 3rd - '-1' and all other - '0'.
Result
1,0,-1,0,0,0,0
Then need to compare 1st number with next - 4th and etc.
- When 1st number will be compared with all other numbers, need to compare 2nd number with 3rd, then with 4th and others.
- When all numbers of 1st row will be compared between each other, need to switch to next row.
How to do this in R?
Innovation,Licensing,Marketing,Portfolio,Purchase,Quality,Support
1,0,-1,0,0,0,0
0,1,-1,0,0,0,0
0,0,-1,1,0,0,0
0,0,-1,0,1,0,0
0,0,-1,0,0,1,0
0,0,-1,0,0,0,1
1,-1,0,0,0,0,0
1,0,-1,0,0,0,0
1,0,0,-1,0,0,0
-1,0,0,0,0,1,0
-1,0,0,0,0,0,1
0,-1,0,0,1,0,0
0,-1,0,0,0,1,0
0,-1,0,0,0,0,1
0,0,-1,0,1,0,0
0,0,-1,0,0,1,0
0,0,-1,0,0,0,1
0,0,0,-1,1,0,0
0,0,0,-1,0,1,0
0,0,0,-1,0,0,1
0,0,0,0,-1,1,0
0,0,0,0,-1,0,1
-1,1,0,0,0,0,0
-1,0,1,0,0,0,0
-1,0,0,1,0,0,0
-1,0,0,0,0,1,0
-1,0,0,0,0,0,1
0,-1,0,1,0,0,0
0,1,0,0,-1,0,0
0,-1,0,0,0,1,0
0,0,-1,1,0,0,0
0,0,1,0,-1,0,0
0,0,-1,0,0,1,0
0,0,0,1,-1,0,0
0,0,0,1,0,0,-1
0,0,0,0,-1,1,0
0,0,0,0,-1,0,1
0,0,0,0,0,1,-1