Skip to content
Prev 369638 / 398503 Next

integrating 2 lists and a data frame in R

Simple matrix indexing suffices without any fancier functionality.

## First convert M and N to character vectors -- which they should
have been in the first place!

M <- sort(as.character(M[,1]))
N <-  sort(as.character(N[,1]))

## This could be a one-liner, but I'll split it up for clarity.

res <-matrix(NA, length(M),length(N),dimnames = list(M,N))

res[as.matrix(C[,2:1])] <- C$I ## matrix indexing

res

Cheers,
Bert


Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Tue, Jun 6, 2017 at 7:46 AM, Bogdan Tanasa <tanasa at gmail.com> wrote: