# [R] R vector

arun smartpink111 at yahoo.com
Tue Jun 11 17:39:22 CEST 2013

```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=TRUE)/ncol(matN)
res<- rbind(resP,resN)
row.names(res)<- c("Mean_Pos","Mean_Neg")
res
}
fun1(mat1)
#         [,1]  [,2] [,3]
#Mean_Pos  0.5  0.25    1
#Mean_Neg -0.5 -1.00    0
A.K.

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

```