[R] How to retrieve data from a matrix

arun smartpink111 at yahoo.com
Fri Nov 16 14:56:28 CET 2012


HI,
Try this:
dat1<-read.csv("matrixGinger.csv",sep="\t")
res<-apply(dat1,1,function(x) names(x)[x<0.0165])
res1<-t(sapply(res,`[`,seq(max(sapply(res,length)))))
res2<-data.frame(id=rownames(res1),res1)
dat2<-read.csv("Gingerdat.csv",sep="\t")
 res3<-merge(dat2,res2,by="id",sort=FALSE))
 res3[1:5,1:5]
#      id status    X1     X2      X3
#1 109530      0 X1537 X32255 X103309
#2 109398      0 X1537 X32255 X103309
#3 109494      0 X1537 X32255 X103309
#4 110077      0 X1537 X32255 X103309
#5 109601      0 X1537 X32255 X103309
A.K.




----- Original Message -----
From: ginger <biino at igm.cnr.it>
To: r-help at r-project.org
Cc: 
Sent: Friday, November 16, 2012 6:27 AM
Subject: [R] How to retrieve data from a matrix

I have a data set (data.txt) containing information on affection status
(1=affected; 0=not affected) for some subjects identified by an ID. Then I
have a sort of correlation matrix of the same subjects (matrix.txt). For
each affected subject in the data set I have to retrieve the IDs of
unaffected subjects from the matrix (if the condition “affected-unaffected
correlation<0.0165” is satisfied) and such IDs should  be placed in new
columns of the data set on the affected subject corresponding row.
Does anybody can help me?
data.txt <http://r.789695.n4.nabble.com/file/n4649721/data.txt>   matrix.txt
<http://r.789695.n4.nabble.com/file/n4649721/matrix.txt>  



--
View this message in context: http://r.789695.n4.nabble.com/How-to-retrieve-data-from-a-matrix-tp4649721.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
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