[R] matching genes to a list of gene groups an built binary data frame
David Winsemius
dwinsemius at comcast.net
Mon Oct 20 19:32:33 CEST 2014
On Oct 20, 2014, at 6:28 AM, Karim Mezhoud wrote:
> Genes <- c("ACACA", "BAX" , "BCL2", "BID", "BAX", "MAPK9")
>
> and a list of group of genes
>
> ListGroup <- list(group1=c("ACACA" ,"AHSA1" ,"AIMP2" , "AKR1B1",
> "AKT1", "AKT1S1"), group2=c("ANXA1" , "AR" , "ARID1A" ,
> "ATM" , "BAK1" , "BAX" ), group3=c("BCL2" , "BCL2L1" ,
> "BCL2L11" , "BECN1" , "BID" , "BIRC2"))
Desired:
> I would like to built a data frame as:
>
> ACACA BAX BCL2 BID BAX MAPK9
> group1 1 0 0 0 0 0
> group2 0 1 0 0 1 0
> group3 0 0 1 1 0 0
>
> sapply(Genes, function(x) as.numeric(sapply(ListGroup, '%in%', x=x) ) )
ACACA BAX BCL2 BID BAX MAPK9
[1,] 1 0 0 0 0 0
[2,] 0 1 0 0 1 0
[3,] 0 0 1 1 0 0
?'%in%'
The x=x asserts that the x value will be used as the first argument to %in% so ListGroup items will be used as the table arguments. It's a matrix, so as.data.frame would be needed to deliver a dfrm.
--
David Winsemius
Alameda, CA, USA
More information about the R-help
mailing list