Hi. I am sure there is a better way in R to do this then using a loop but I am new to it and not sure what to do. I think it might be something about using a function as an argument but not sure. I have a 1 x 2000 vector TS2 which has entries from the set {x: x is in Z and 0<x<8} (where Z is the set of Integers). Then I also have a 5050 x 7 matrix called 'perm' whose entries are also from the set {x: x is in Z and 0<x<8} I want to construct the following transformation of TS2 which will still be a vector of size 1 x 2000 and which I will call 'newTS2' such that: newTS2 =(perm[100.TS2[1]]. perm[100.TS2[2]]. perm[100.TS2[3]]. ... , perm[100.TS2[2000]]) Is there a nice way to do this without a loop? Thank you. -- View this message in context: http://www.nabble.com/how-to-do-this-%22the-R-way%22-tp22864354p22864354.html Sent from the R help mailing list archive at Nabble.com.
onyourmark wrote:> Hi. I am sure there is a better way in R to do this then using a loop but I > am new to it and not sure what to do. I think it might be something about > using a function as an argument but not sure. > > I have a 1 x 2000 vector TS2 which has entries from the set {x: x is in Z > and 0<x<8} (where Z is the set of Integers). > > Then I also have a 5050 x 7 matrix called 'perm' whose entries are also from > the set {x: x is in Z and 0<x<8} > > I want to construct the following transformation of TS2 which will still be > a vector of size 1 x 2000 and which I will call 'newTS2' such that: > > newTS2 =(perm[100.TS2[1]]. perm[100.TS2[2]]. perm[100.TS2[3]]. ... ,Perhaps you can explain what the last line is supposed to do? This is invalid R code and also not a known mathematical notation for me .... Uwe Ligges> perm[100.TS2[2000]]) > > Is there a nice way to do this without a loop? > > Thank you.