Re: [R] R vector

2013-06-11 Thread arun
HI, Not sure if this is what you wanted. mat1<- matrix(c(1, 1, -1, -1, 1, -1, -1, -2, 1, 1, 1, 1), byrow=TRUE, nc=4) fun1<- function(mat){     matP<- mat     matN<- mat     matP[matP<0]<- NA     matN[matN>0]<- NA     resP<-rowSums(matP,na.rm=TRUE)/ncol(matP)     resN<- rowSums(matN,na.rm=TRU

Re: [R] R vector

2013-06-11 Thread Adams, Jean
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 wrote

Re: [R] R vector

2013-06-11 Thread Rui Barradas
Hello, You can write your own function, allowing for a condition argument. rowMeansCond <- function(x, cond = ">", na.rm= FALSE){ rowm <- function(x, cond = ">", na.rm = FALSE){ f <- function(x){ eval(parse(text = paste("x", cond, "0")))

[R] R vector

2013-06-11 Thread felice
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