[R] unfurling rankings into a matrix of preferences

2015-07-27 Thread Dimitri Liakhovitski
I have 5 items in total (1:5), but I show a person only 4 items (1:4)
and ask this person to rank items 1:4 in terms of preferences (1 is
best, 2 is second best, 4 is worst), and I get a vector of ranks:
ranks - c(2,4,3,1)

# That means that this person liked item 4 best and item 2 worst.

I would like to unfirl this vector of ranks into a matrix of
preferences where if the row item prefers the column item, then it's a
1. Otherwise, it's a zero. So, the output should be a 5 by 5 matrix
(because overall we have 5 items, not 4, but item 5 did not
participate in rankings), and it would always have zeros in a
diagonal.:

0110 NA
0000 NA
0100 NA
1110 NA
NA NA NA NA 0

I can loop through all possible pairs the person saw and fill the
matrix accordingly, but it seems like a lot of looping. Could one do
it in a more elegant way?

Thank you very much!


-- 
Dimitri Liakhovitski

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] unfurling rankings into a matrix of preferences

2015-07-27 Thread Bert Gunter
## I leave it to you to add the NA edges

 rk - c(2,4,3,1)

 outer(rk,rk,)+0

 [,1] [,2] [,3] [,4]
[1,]0110
[2,]0000
[3,]0100
[4,]1110



Cheers,
Bert

Bert Gunter

Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom.
   -- Clifford Stoll


On Mon, Jul 27, 2015 at 12:38 PM, Dimitri Liakhovitski
dimitri.liakhovit...@gmail.com wrote:
 I have 5 items in total (1:5), but I show a person only 4 items (1:4)
 and ask this person to rank items 1:4 in terms of preferences (1 is
 best, 2 is second best, 4 is worst), and I get a vector of ranks:
 ranks - c(2,4,3,1)

 # That means that this person liked item 4 best and item 2 worst.

 I would like to unfirl this vector of ranks into a matrix of
 preferences where if the row item prefers the column item, then it's a
 1. Otherwise, it's a zero. So, the output should be a 5 by 5 matrix
 (because overall we have 5 items, not 4, but item 5 did not
 participate in rankings), and it would always have zeros in a
 diagonal.:

 0110 NA
 0000 NA
 0100 NA
 1110 NA
 NA NA NA NA 0

 I can loop through all possible pairs the person saw and fill the
 matrix accordingly, but it seems like a lot of looping. Could one do
 it in a more elegant way?

 Thank you very much!


 --
 Dimitri Liakhovitski

 __
 R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] unfurling rankings into a matrix of preferences

2015-07-27 Thread Dimitri Liakhovitski
Wow!

On Mon, Jul 27, 2015 at 5:28 PM, Bert Gunter bgunter.4...@gmail.com wrote:
 ## I leave it to you to add the NA edges

 rk - c(2,4,3,1)

 outer(rk,rk,)+0

  [,1] [,2] [,3] [,4]
 [1,]0110
 [2,]0000
 [3,]0100
 [4,]1110



 Cheers,
 Bert

 Bert Gunter

 Data is not information. Information is not knowledge. And knowledge
 is certainly not wisdom.
-- Clifford Stoll


 On Mon, Jul 27, 2015 at 12:38 PM, Dimitri Liakhovitski
 dimitri.liakhovit...@gmail.com wrote:
 I have 5 items in total (1:5), but I show a person only 4 items (1:4)
 and ask this person to rank items 1:4 in terms of preferences (1 is
 best, 2 is second best, 4 is worst), and I get a vector of ranks:
 ranks - c(2,4,3,1)

 # That means that this person liked item 4 best and item 2 worst.

 I would like to unfirl this vector of ranks into a matrix of
 preferences where if the row item prefers the column item, then it's a
 1. Otherwise, it's a zero. So, the output should be a 5 by 5 matrix
 (because overall we have 5 items, not 4, but item 5 did not
 participate in rankings), and it would always have zeros in a
 diagonal.:

 0110 NA
 0000 NA
 0100 NA
 1110 NA
 NA NA NA NA 0

 I can loop through all possible pairs the person saw and fill the
 matrix accordingly, but it seems like a lot of looping. Could one do
 it in a more elegant way?

 Thank you very much!


 --
 Dimitri Liakhovitski

 __
 R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.



-- 
Dimitri Liakhovitski

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] unfurling rankings into a matrix of preferences

2015-07-27 Thread Dimitri Liakhovitski
With NAs it'd be:

rk - c(2,NA,4,3,1, NA)
outer(rk, rk, ) + 0

Wow, I still can't believe it - just one line!


On Mon, Jul 27, 2015 at 5:31 PM, Dimitri Liakhovitski
dimitri.liakhovit...@gmail.com wrote:
 Wow!

 On Mon, Jul 27, 2015 at 5:28 PM, Bert Gunter bgunter.4...@gmail.com wrote:
 ## I leave it to you to add the NA edges

 rk - c(2,4,3,1)

 outer(rk,rk,)+0

  [,1] [,2] [,3] [,4]
 [1,]0110
 [2,]0000
 [3,]0100
 [4,]1110



 Cheers,
 Bert

 Bert Gunter

 Data is not information. Information is not knowledge. And knowledge
 is certainly not wisdom.
-- Clifford Stoll


 On Mon, Jul 27, 2015 at 12:38 PM, Dimitri Liakhovitski
 dimitri.liakhovit...@gmail.com wrote:
 I have 5 items in total (1:5), but I show a person only 4 items (1:4)
 and ask this person to rank items 1:4 in terms of preferences (1 is
 best, 2 is second best, 4 is worst), and I get a vector of ranks:
 ranks - c(2,4,3,1)

 # That means that this person liked item 4 best and item 2 worst.

 I would like to unfirl this vector of ranks into a matrix of
 preferences where if the row item prefers the column item, then it's a
 1. Otherwise, it's a zero. So, the output should be a 5 by 5 matrix
 (because overall we have 5 items, not 4, but item 5 did not
 participate in rankings), and it would always have zeros in a
 diagonal.:

 0110 NA
 0000 NA
 0100 NA
 1110 NA
 NA NA NA NA 0

 I can loop through all possible pairs the person saw and fill the
 matrix accordingly, but it seems like a lot of looping. Could one do
 it in a more elegant way?

 Thank you very much!


 --
 Dimitri Liakhovitski

 __
 R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.



 --
 Dimitri Liakhovitski



-- 
Dimitri Liakhovitski

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] unfurling rankings into a matrix of preferences

2015-07-27 Thread Bert Gunter
No it wouldn't.

Presumably you have a typo and meant

rk - c(2,4,3,1,NA)

## and set the (5,5) entry to 0 after

-- Bert


Bert Gunter

Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom.
   -- Clifford Stoll


On Mon, Jul 27, 2015 at 2:32 PM, Dimitri Liakhovitski
dimitri.liakhovit...@gmail.com wrote:
 With NAs it'd be:

 rk - c(2,NA,4,3,1, NA)
 outer(rk, rk, ) + 0

 Wow, I still can't believe it - just one line!


 On Mon, Jul 27, 2015 at 5:31 PM, Dimitri Liakhovitski
 dimitri.liakhovit...@gmail.com wrote:
 Wow!

 On Mon, Jul 27, 2015 at 5:28 PM, Bert Gunter bgunter.4...@gmail.com wrote:
 ## I leave it to you to add the NA edges

 rk - c(2,4,3,1)

 outer(rk,rk,)+0

  [,1] [,2] [,3] [,4]
 [1,]0110
 [2,]0000
 [3,]0100
 [4,]1110



 Cheers,
 Bert

 Bert Gunter

 Data is not information. Information is not knowledge. And knowledge
 is certainly not wisdom.
-- Clifford Stoll


 On Mon, Jul 27, 2015 at 12:38 PM, Dimitri Liakhovitski
 dimitri.liakhovit...@gmail.com wrote:
 I have 5 items in total (1:5), but I show a person only 4 items (1:4)
 and ask this person to rank items 1:4 in terms of preferences (1 is
 best, 2 is second best, 4 is worst), and I get a vector of ranks:
 ranks - c(2,4,3,1)

 # That means that this person liked item 4 best and item 2 worst.

 I would like to unfirl this vector of ranks into a matrix of
 preferences where if the row item prefers the column item, then it's a
 1. Otherwise, it's a zero. So, the output should be a 5 by 5 matrix
 (because overall we have 5 items, not 4, but item 5 did not
 participate in rankings), and it would always have zeros in a
 diagonal.:

 0110 NA
 0000 NA
 0100 NA
 1110 NA
 NA NA NA NA 0

 I can loop through all possible pairs the person saw and fill the
 matrix accordingly, but it seems like a lot of looping. Could one do
 it in a more elegant way?

 Thank you very much!


 --
 Dimitri Liakhovitski

 __
 R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide 
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.



 --
 Dimitri Liakhovitski



 --
 Dimitri Liakhovitski

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] unfurling rankings into a matrix of preferences

2015-07-27 Thread Dimitri Liakhovitski
Yes, correct, thank you, Bert!

On Mon, Jul 27, 2015 at 5:46 PM, Bert Gunter bgunter.4...@gmail.com wrote:
 No it wouldn't.

 Presumably you have a typo and meant

 rk - c(2,4,3,1,NA)

 ## and set the (5,5) entry to 0 after

 -- Bert


 Bert Gunter

 Data is not information. Information is not knowledge. And knowledge
 is certainly not wisdom.
-- Clifford Stoll


 On Mon, Jul 27, 2015 at 2:32 PM, Dimitri Liakhovitski
 dimitri.liakhovit...@gmail.com wrote:
 With NAs it'd be:

 rk - c(2,NA,4,3,1, NA)
 outer(rk, rk, ) + 0

 Wow, I still can't believe it - just one line!


 On Mon, Jul 27, 2015 at 5:31 PM, Dimitri Liakhovitski
 dimitri.liakhovit...@gmail.com wrote:
 Wow!

 On Mon, Jul 27, 2015 at 5:28 PM, Bert Gunter bgunter.4...@gmail.com wrote:
 ## I leave it to you to add the NA edges

 rk - c(2,4,3,1)

 outer(rk,rk,)+0

  [,1] [,2] [,3] [,4]
 [1,]0110
 [2,]0000
 [3,]0100
 [4,]1110



 Cheers,
 Bert

 Bert Gunter

 Data is not information. Information is not knowledge. And knowledge
 is certainly not wisdom.
-- Clifford Stoll


 On Mon, Jul 27, 2015 at 12:38 PM, Dimitri Liakhovitski
 dimitri.liakhovit...@gmail.com wrote:
 I have 5 items in total (1:5), but I show a person only 4 items (1:4)
 and ask this person to rank items 1:4 in terms of preferences (1 is
 best, 2 is second best, 4 is worst), and I get a vector of ranks:
 ranks - c(2,4,3,1)

 # That means that this person liked item 4 best and item 2 worst.

 I would like to unfirl this vector of ranks into a matrix of
 preferences where if the row item prefers the column item, then it's a
 1. Otherwise, it's a zero. So, the output should be a 5 by 5 matrix
 (because overall we have 5 items, not 4, but item 5 did not
 participate in rankings), and it would always have zeros in a
 diagonal.:

 0110 NA
 0000 NA
 0100 NA
 1110 NA
 NA NA NA NA 0

 I can loop through all possible pairs the person saw and fill the
 matrix accordingly, but it seems like a lot of looping. Could one do
 it in a more elegant way?

 Thank you very much!


 --
 Dimitri Liakhovitski

 __
 R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide 
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.



 --
 Dimitri Liakhovitski



 --
 Dimitri Liakhovitski



-- 
Dimitri Liakhovitski

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.