[R] populating matrix with binary variable after matching data from data frame

arun smartpink111 at yahoo.com
Wed Aug 13 05:27:23 CEST 2014


You could try:
x1$V2[1] <- "TCLA1"


  x[outer(rownames(x), colnames(x), FUN=paste) %in% as.character(interaction(x1, sep=" "))] <- 1
x
       TCLA1 VPS41 ABCA13 ABCA4
AKT3       1     0      0     0
AKTIP      0     1      0     0
ABCA13     0     0      0     0
ABCA4      0     0      0     0
A.K.


On Tuesday, August 12, 2014 8:16 PM, Adrian Johnson <oriolebaltimore at gmail.com> wrote:
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]]

______________________________________________
R-help at r-project.org mailing list
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.



More information about the R-help mailing list