Skip to content
Prev 343086 / 398506 Next

populating matrix with binary variable after matching data from data frame

On Tue, Aug 12, 2014 at 7:14 PM, Adrian Johnson <oriolebaltimore at gmail.com>
wrote:
<snip>

I'm not totally sure that I understand your data structure. So I will
rephrase a bit so that I can be corrected, if necessary. You have an
1211x1121 matrix already. Every cell in the matrix is initialized to 0. It
has column names such as TCLA1, VPS41, ABCA13, ABCA4, ... and it has row
names such as AKT3 AKTPI, ABCA13, ABCA4. The list "x1" has columns named V1
and V2. V1 values are row names in the matrix. V2 values are column names
in the matrix. The following should do what you want. It is not a _good_
solution because it is iterative. But it is a start

for (i in nrow(x1)) {
   x[x1$V1[i], x1$V2[i]] <- 1;
}
Please post in plain text, per the mailing list "rules".