[R] populating matrix with binary variable after matching data from data frame
Adrian Johnson
oriolebaltimore at gmail.com
Wed Aug 13 02:14:50 CEST 2014
Hi:
sorry I have a basic question.
I have a data frame with two columns:
> x1
V1 V2
1 AKT3 TCL1A
2 AKTIP VPS41
3 AKTIP PDPK1
4 AKTIP GTF3C1
5 AKTIP HOOK2
6 AKTIP POLA2
7 AKTIP KIAA1377
8 AKTIP FAM160A2
9 AKTIP VPS16
10 AKTIP VPS18
I have a matrix 1211x1211 (using some elements in x1$V1 and some from
x1$V2). I want to populate for every match for example AKT3 = TCL1A = 1
whereas AKT3 - VPS41 gets 0)
How can i map this binary relations in x.
>x
TCLA1 VPS41 ABCA13 ABCA4
AKT3 0 0 0 0
AKTIP 0 0 0 0
ABCA13 0 0 0 0
ABCA4 0 0 0 0
dput -
x = structure(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), .Dim =
c(4L,
4L), .Dimnames = list(c("AKT3", "AKTIP", "ABCA13", "ABCA4"
), c("TCLA1", "VPS41", "ABCA13", "ABCA4")))
x1 = structure(list(V1 = c("AKT3", "AKTIP", "AKTIP", "AKTIP", "AKTIP",
"AKTIP", "AKTIP", "AKTIP", "AKTIP", "AKTIP"), V2 = c("TCL1A",
"VPS41", "PDPK1", "GTF3C1", "HOOK2", "POLA2", "KIAA1377", "FAM160A2",
"VPS16", "VPS18")), .Names = c("V1", "V2"), row.names = c(NA,
10L), class = "data.frame")
Thanks
Adrian
[[alternative HTML version deleted]]
More information about the R-help
mailing list