Hi guys, one of the questions where you need a real human instead of a search engine, so it would be great if you could help. I have a matrix of z-scores which I would like to filter, sometimes columnwise, sometimes rowwise. Data looks like this: Allstar hsa.let.7a hsa.let.7a.1 hsa.let.7a.2 2 0.87 0.79 -0.57 1.07 3 0.67 -1.14 -0.78 -0.95 4 -0.46 -0.30 -0.36 1.14 Now I want to find all elements which are below/above some threshold. Subset works fine with the columns:> subset(red[,4], red[,4] > 0.5)[1] 1.07 1.14 But not with the rows:> subset(red[2,], red[2,] > 0.5)Allstar hsa.let.7a hsa.let.7a.1 hsa.let.7a.2 3 0.67 -1.14 -0.78 -0.95 If I try to find all values above 0.5 (any row, any column, I just need the number of entries), this is what I try (and get):> subset(red[,], red[,] > 0.5)Allstar hsa.let.7a hsa.let.7a.1 hsa.let.7a.2 2 0.87 0.79 -0.57 1.07 3 0.67 -1.14 -0.78 -0.95 NA NA NA NA NA NA.1 NA NA NA NA NA.2 NA NA NA NA Obviously I'm doing something wrong, but what? Help very much appreciated. Netzwerkerin -- View this message in context: http://r.789695.n4.nabble.com/subsetting-tables-tp3793509p3793509.html Sent from the R help mailing list archive at Nabble.com.
Sorry If I miss the point you want to achieve, but why not just: which(red > 0.5) or red[which(red > 0.5)] if you want to use this col/row wise you could do: apply(red, 1, function(x)x[x>0.5]) and apply(red, 1, function(x)x[x>0.5]) ? --- netzwerkerin <lehmannk at informatik.uni-tuebingen.de> schrieb am Di, 6.9.2011:> Von: netzwerkerin <lehmannk at informatik.uni-tuebingen.de> > Betreff: [R] subsetting tables > An: r-help at r-project.org > Datum: Dienstag, 6. September, 2011 14:10 Uhr > Hi guys, > > one of the questions where you need a real human instead of > a search engine, > so it would be great if you could help. > > I have a matrix of z-scores which I would like to filter, > sometimes > columnwise, sometimes rowwise. Data looks like this: > > ? Allstar hsa.let.7a hsa.let.7a.1 hsa.let.7a.2 > 2? ? 0.87? ? > ???0.79? ? ? ? > -0.57? ? ? ???1.07 > 3? ? 0.67? ? ? -1.14? ? > ? ? -0.78? ? ? ? -0.95 > 4???-0.46? ? ? -0.30? > ? ? ? -0.36? ? ? > ???1.14 > > Now I want to find all elements which are below/above some > threshold. Subset > works fine with the columns: > > > subset(red[,4], red[,4] > 0.5) > [1] 1.07 1.14 > > But not with the rows: > > > subset(red[2,], red[2,] > 0.5) > ? Allstar hsa.let.7a hsa.let.7a.1 hsa.let.7a.2 > 3? ? 0.67? ? ? -1.14? ? > ? ? -0.78? ? ? ? -0.95 > > If I try to find all values above 0.5 (any row, any column, > I just need the > number of entries), this is what I try (and get): > > > subset(red[,], red[,] > 0.5) > ? ???Allstar hsa.let.7a hsa.let.7a.1 > hsa.let.7a.2 > 2? ? ???0.87? ? > ???0.79? ? ? ? > -0.57? ? ? ???1.07 > 3? ? ???0.67? ? ? > -1.14? ? ? ? -0.78? ? ? > ? -0.95 > NA? ? ? ? NA? ? ? > ???NA? ? ? ? > ???NA? ? ? ? > ???NA > NA.1? ? ? NA? ? ? > ???NA? ? ? ? > ???NA? ? ? ? > ???NA > NA.2? ? ? NA? ? ? > ???NA? ? ? ? > ???NA? ? ? ? > ???NA > > Obviously I'm doing something wrong, but what? > Help very much appreciated. > Netzwerkerin > > -- > View this message in context: http://r.789695.n4.nabble.com/subsetting-tables-tp3793509p3793509.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. >
Hi Netzwerkerin, subset is a generic function and behaves different for different object classes. txt<-" Allstar hsa.let.7a hsa.let.7a.1 hsa.let.7a.2 2 0.87 0.79 -0.57 1.07 3 0.67 -1.14 -0.78 -0.95 4 -0.46 -0.30 -0.36 1.14" red<-read.table(textConnection(txt)) #compare str(red[,2]) str(red[2,]) but if it comes to just counting values meeting some conditions, using "subset" is not needed at all. sum(red>.5) length(which(red>.5)) and the arr.ind option of which may be useful as well. hth Am 06.09.2011 16:10, schrieb netzwerkerin:> Hi guys, > > one of the questions where you need a real human instead of a search engine, > so it would be great if you could help. > > I have a matrix of z-scores which I would like to filter, sometimes > columnwise, sometimes rowwise. Data looks like this: > > Allstar hsa.let.7a hsa.let.7a.1 hsa.let.7a.2 > 2 0.87 0.79 -0.57 1.07 > 3 0.67 -1.14 -0.78 -0.95 > 4 -0.46 -0.30 -0.36 1.14 > > Now I want to find all elements which are below/above some threshold. Subset > works fine with the columns: > >> subset(red[,4], red[,4] > 0.5) > [1] 1.07 1.14 > > But not with the rows: > >> subset(red[2,], red[2,] > 0.5) > Allstar hsa.let.7a hsa.let.7a.1 hsa.let.7a.2 > 3 0.67 -1.14 -0.78 -0.95 > > If I try to find all values above 0.5 (any row, any column, I just need the > number of entries), this is what I try (and get): > >> subset(red[,], red[,] > 0.5) > Allstar hsa.let.7a hsa.let.7a.1 hsa.let.7a.2 > 2 0.87 0.79 -0.57 1.07 > 3 0.67 -1.14 -0.78 -0.95 > NA NA NA NA NA > NA.1 NA NA NA NA > NA.2 NA NA NA NA > > Obviously I'm doing something wrong, but what? > Help very much appreciated. > Netzwerkerin > > -- > View this message in context: http://r.789695.n4.nabble.com/subsetting-tables-tp3793509p3793509.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.-- Eik Vettorazzi Department of Medical Biometry and Epidemiology University Medical Center Hamburg-Eppendorf Martinistr. 52 20246 Hamburg T ++49/40/7410-58243 F ++49/40/7410-57790 -- Pflichtangaben gem?? Gesetz ?ber elektronische Handelsregister und Genossenschaftsregister sowie das Unternehmensregister (EHUG): Universit?tsklinikum Hamburg-Eppendorf; K?rperschaft des ?ffentlichen Rechts; Gerichtsstand: Hamburg Vorstandsmitglieder: Prof. Dr. J?rg F. Debatin (Vorsitzender), Dr. Alexander Kirstein, Joachim Pr?l?, Prof. Dr. Dr. Uwe Koch-Gromus