[R] how to do this?

Luca Braglia braglia at poleis.eu
Fri Sep 11 10:17:12 CEST 2009


Hello R-users

I have a situation like this

x=c(1,3,2)

y=data.frame("a"=1:3, "b"=4:6, "c"=7:9)*2

So we have

> t(t(x))
     [,1]
[1,]    1
[2,]    3
[3,]    2

And

> y
  a  b  c
1 2  8 14
2 4 10 16
3 6 12 18

I would like to obtain a vector with number taken from the data.frame: x is needed as row index 

With c(1,3,2), in this case the ouput should be

2
16
12

I've tried a little bit with apply, but unsuccessfully.

Thank you




More information about the R-help mailing list