[R] Help "deleting negative values in a matrix, and do statistic analysis"

Rui Barradas ruipbarradas at sapo.pt
Tue May 8 17:33:29 CEST 2012


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.



More information about the R-help mailing list