Peter Davidsen
2011-Nov-20 22:45 UTC
[R] Deleting multiple rows from a data matrix based on exp value
Dear List, I have a data matrix that consists of ~4500 rows and 25 columns (i.e. an exprSet object that I converted via the 'exprs' function into a data matrix) Now I want to remove/delete the rows where all exp. values in that particular row are below or equal to a specific cut-off value (e.g 1.11) I have tried using several commands to address this issue:>Matrix[rowSums(Matrix <= 1.11) <= 1.11, ]or>Matrix[ !apply(Matrix<=1.11,1,all), ]The above commands seem to work fine when I generate a small "test" matrix like:>M <- matrix(c(2,5,8,0.4,0.8,0.5,4,12,3), nrow=3, byrow=T)However, non of the two commands decrease the number of rows in my real matrix! Any help would be appreciated Kind regards, Peter
Dennis Murphy
2011-Nov-21 05:09 UTC
[R] Deleting multiple rows from a data matrix based on exp value
Without a reproducible example this is just a guess, but try Matrix[apply(Matrix, 1, function(x) any(x > 1.11)), ] This will retain all rows of Matrix where at least one value in a row is above the threshold 1.11. If that doesn't do what you want, please provide a small reproducible example and a clearer statement of the desired output. It's not at all clear to me what 'exp. values' means - I can devise at least three meanings off the top of my head, none of which may conform to what you mean. HTH, Dennis On Sun, Nov 20, 2011 at 2:45 PM, Peter Davidsen <pkdavidsen at gmail.com> wrote:> Dear List, > > I have a data matrix that consists of ~4500 rows and 25 columns (i.e. > an exprSet object that I converted via the 'exprs' function into a > data matrix) > > Now I want to remove/delete the rows where all exp. values in that > particular row are below or equal to a specific cut-off value (e.g > 1.11) > > I have tried using several commands to address this issue: >>Matrix[rowSums(Matrix <= 1.11) <= 1.11, ] > > or > >>Matrix[ !apply(Matrix<=1.11,1,all), ] > > > The above commands seem to work fine when I generate a small "test" matrix like: >>M <- matrix(c(2,5,8,0.4,0.8,0.5,4,12,3), nrow=3, byrow=T) > > However, non of the two commands decrease the number of rows in my real matrix! > > Any help would be appreciated > > Kind regards, > Peter > > ______________________________________________ > 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. >
Possibly Parallel Threads
- Error: cannot allocate vector of size...
- expression matrix
- problem with creation of eSet
- Error in function (classes, fdef, mtable): unable to find an inherited method for function "indexProbes", for signature "exprSet", "character"
- basic subset question of matrix