madr
2010-Dec-08 15:54 UTC
[R] how to make partial mean() of a matrix only when second value matching some logic
for example I have matrix with two columns x,y 1,0.56 2,9.55 2,7.56 5,2.55 5,0.56 3,0.55 2,0.56 2,1.56 so I need to take average from y values placed where x==2 -- View this message in context: http://r.789695.n4.nabble.com/how-to-make-partial-mean-of-a-matrix-only-when-second-value-matching-some-logic-tp3078449p3078449.html Sent from the R help mailing list archive at Nabble.com.
Mike Rennie
2010-Dec-08 16:00 UTC
[R] how to make partial mean() of a matrix only when second value matching some logic
try tapply() if you want the values for all levels of x, or calculate your mean after a subset() Check the documentation on both of these. Mike On Wed, Dec 8, 2010 at 9:54 AM, madr <madrazel@interia.pl> wrote:> > for example I have matrix with two columns > > x,y > 1,0.56 > 2,9.55 > 2,7.56 > 5,2.55 > 5,0.56 > 3,0.55 > 2,0.56 > 2,1.56 > > so I need to take average from y values placed where x==2 > -- > View this message in context: > http://r.789695.n4.nabble.com/how-to-make-partial-mean-of-a-matrix-only-when-second-value-matching-some-logic-tp3078449p3078449.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<http://www.r-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. >-- Michael Rennie, Research Scientist Fisheries and Oceans Canada, Freshwater Institute Winnipeg, Manitoba, CANADA [[alternative HTML version deleted]]
Apparently Analagous Threads
- increase or decrease variable by 1
- how to get rid of unused space on all 4 borders in plot() render
- please show me simple example how to plot "Distance-Weighted Least Squares" fitting
- how to strip list from NA values looking only at one column ?
- "negative alpha" or custom gradient colors of data dots in scatterplot ?