[R] S. function calculating x +- y

Gabor Grothendieck ggrothendieck at gmail.com
Fri Mar 4 18:43:14 CET 2011


On Fri, Mar 4, 2011 at 12:22 PM, Sascha Vieweg <saschaview at gmail.com> wrote:
> Hello, I am looking for an elegant one-liner for the following operation:
>
> x <- rnorm(10)
> y <- runif(10)
> c(mean(x)-mean(y), mean(x)+mean(y))
>
> I thought about
>
> apply(data.frame(x, y), 2, mean)
>
> but I don't know how to apply the +- operation on the result of apply.

Try:

mean(x) + c(-1, 1) * mean(y)



-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



More information about the R-help mailing list