Skip to content

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

6 messages · Rui Barradas, york8866, John Kane

#
Hello,

Try
(x is your matrix)

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


Hope this helps,

Rui Barradas

york8866 wrote
--
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.
#
It looks fine to me. Why do you say it does not work?

Any error messages?

John Kane
Kingston ON Canada
____________________________________________________________
FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!
#
Hi, John,

the code ran well.

however, somehow, the means were not calculated correctly using the
following code.

test <- read.csv("Rtestdataset.csv", as.is=T,header=T)  
test <- data.frame(test)
test
rowMeans(test)
apply(test,1,function(y)mean(y>=0))

Is there anything wrong?
thanks,



--
View this message in context: http://r.789695.n4.nabble.com/Help-deleting-negative-values-in-a-matrix-and-do-statistic-analysis-tp4617792p4618247.html
Sent from the R help mailing list archive at Nabble.com.
#
Hello,


york8866 wrote
Yes!!!

It's mean( y[y >= 0] )

Rui Barradas


--
View this message in context: http://r.789695.n4.nabble.com/Help-deleting-negative-values-in-a-matrix-and-do-statistic-analysis-tp4617792p4618267.html
Sent from the R help mailing list archive at Nabble.com.
#
Sorry, my mistake.

it works very well!!!

thanks,



Rui Barradas wrote
--
View this message in context: http://r.789695.n4.nabble.com/Help-deleting-negative-values-in-a-matrix-and-do-statistic-analysis-tp4617792p4618379.html
Sent from the R help mailing list archive at Nabble.com.