Not quite sure if this is what you're after ... but perhaps it will help. m <- matrix(c(1, 1, -1, -1, 1, -1, -1, -2, 1, 1, 1, 1), byrow=TRUE, ncol=4) apply(m, 1, function(x) sum(x[x>0]))/dim(m)[2] apply(m, 1, function(x) sum(x[x<0]))/dim(m)[2]
Jean On Tue, Jun 11, 2013 at 7:18 AM, felice <felix1...@gmx.de> wrote: > hello, > > when i use the function rowMeans, which is sum/n, can i divide it in 2 > parts, -> Sum(just positive values)/n and Sum(just negative values)/n. i > need both for my regression but dont know how to do it. > > for example we have the matrix > > 1 1 -1 -1 -> rowMeans([1:3 , 2]) just positive -> 1 > 1 -1 -1 -2 > 1/2 here not 0 because we dont use the -1 > 1 1 1 1 > 1 > > > thanks for helping > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/R-vector-tp4669233.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@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. > [[alternative HTML version deleted]] ______________________________________________ R-help@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.