[R] performing function on data frame

Karin Lagesen karinlag at ifi.uio.no
Wed Apr 15 14:59:22 CEST 2009


Hi!

First, pardon me if this is a faq. I think I should be using some sort
of apply, but I am not managing to figure those out.

I have a data frame similar to this:

> d <- data.frame(x = LETTERS[1:5], y = rnorm(5), z = rnorm(5))
> d
  x          y          z
1 A  0.1605464 -0.2719820
2 B -0.9258660  1.2623117
3 C -0.3602656  1.5470351
4 D  1.2621797  1.2996500
5 E  0.6021728  0.5027095
> 

>From this I want to get a new data frame which contains the z scores
based on the values found in each row. For instance for element [C,y],
I would like to calculate (-0.3602656 - mean(column y)/stddev(column
y)).

Thanks!
-- 
Karin Lagesen, Ph.D.
karin.lagesen at medisin.uio.no
http://folk.uio.no/karinlag




More information about the R-help mailing list