Lida Zeighami
2015-Jul-08 15:37 UTC
[R] select a subset of a matrix which one of its column meet a condition
Hi there, I have a matrix and I want to get a subset from that which one of its matrix meet a condition, my matrix is met Row.names Name maf caf 1 10:100003915 10:1000039 0.0003782148 0.0003782148 2 10:100008738 10:100008738 0.0003759398 0.0003759398 3 10:100011321 10:100011321 0.0003762227 0.0003762227 4 10:100012219 10:100012219 0.0007518797 0.0007518797 5 10:100013325 10:100013325 0.0000000000 0.0000000000 6 10:100015404 10:100015404 0.0000000000 0.0000000000 I want to choose a subset from "met" which maf values are between 0 and 0.05 (0,0.05) I wrote this code, but seem doesn't work properly:> maf<- met[which(c(met[,5]) %in% c(0,0.05)),]the dim(maf) is 0 so seems my code didn't work! would please let me know how to correct it? Thanks [[alternative HTML version deleted]]
Rui Barradas
2015-Jul-08 17:06 UTC
[R] select a subset of a matrix which one of its column meet a condition
Hello, Your matrix has only 4 columns but you refer to met[,5]. I'll assume you're refering to the last column, met[,4]. Try reading the help page for ?%in%, it doesn't do what you seem to think it does. And try using <=. maf <- met[0 <= met[, 4] & met[, 4] <= 0.05, ] Hope this helps, Rui Barradas Em 08-07-2015 16:37, Lida Zeighami escreveu:> Hi there, > > I have a matrix and I want to get a subset from that which one of its > matrix meet a condition, > > my matrix is > met > Row.names Name > maf caf > 1 10:100003915 10:1000039 0.0003782148 > 0.0003782148 > 2 10:100008738 10:100008738 0.0003759398 > 0.0003759398 > 3 10:100011321 10:100011321 0.0003762227 > 0.0003762227 > 4 10:100012219 10:100012219 0.0007518797 > 0.0007518797 > 5 10:100013325 10:100013325 0.0000000000 > 0.0000000000 > 6 10:100015404 10:100015404 0.0000000000 > 0.0000000000 > > I want to choose a subset from "met" which maf values are between 0 and > 0.05 (0,0.05) > > I wrote this code, but seem doesn't work properly: > >> maf<- met[which(c(met[,5]) %in% c(0,0.05)),] > > the dim(maf) is 0 so seems my code didn't work! > would please let me know how to correct it? > > Thanks > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. >