Hello,

Try
(x is your matrix)

rowMeans(x)
apply(x, 1, function(y) mean( y[y >= 0] ))


Hope this helps,

Rui Barradas

york8866 wrote
> 
> Dear all,
> 
> I have encountered a problem with such a dataset:
> 
> 1     52      2       5       2       6
> 15    23      2       1       3       3
> 2     5       1       9       8       9
> 6     -5      3       6       -5      96
> -1    6       3       8       5       9
> .     .       .       .       .       .
> .     .       .       .       .       .
> 
> 
> I want to calculate the means of each row of the dataset. In addition, I
> need to delete the negative values in each row first before the
> calculation of the means.
> 
> can anyone show me how to deal with it?
> 
> thanks,
> 


--
View this message in context: 
http://r.789695.n4.nabble.com/Help-deleting-negative-values-in-a-matrix-and-do-statistic-analysis-tp4617792p4617832.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.

Reply via email to