Rui Barradas
2012-May-08 15:33 UTC
[R] Help "deleting negative values in a matrix, and do statistic analysis"
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.
york8866
2012-May-08 17:06 UTC
[R] Help "deleting negative values in a matrix, and do statistic analysis"
Hi, Rui, I tried your code. It did not work. thanks, -- View this message in context: http://r.789695.n4.nabble.com/Help-deleting-negative-values-in-a-matrix-and-do-statistic-analysis-tp4617792p4618080.html Sent from the R help mailing list archive at Nabble.com.
John Kane
2012-May-08 17:59 UTC
[R] Help "deleting negative values in a matrix, and do statistic analysis"
It looks fine to me. Why do you say it does not work? Any error messages? John Kane Kingston ON Canada> -----Original Message----- > From: yu_york at hotmail.com > Sent: Tue, 8 May 2012 10:06:07 -0700 (PDT) > To: r-help at r-project.org > Subject: Re: [R] Help "deleting negative values in a matrix, and do > statistic analysis" > > Hi, Rui, > > I tried your code. It did not work. > > thanks, > > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/Help-deleting-negative-values-in-a-matrix-and-do-statistic-analysis-tp4617792p4618080.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at 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.____________________________________________________________ FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!
york8866
2012-May-08 18:12 UTC
[R] Help "deleting negative values in a matrix, and do statistic analysis"
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.