[R] Small vector into large data frame

Francesca Pancotto francesca.pancotto at unimore.it
Fri Nov 14 15:48:57 CET 2014


Dear Contributors
I seem not to get the general rule applying to the use of loops.
I need some help. I have a database in which i need to generate a variable according to the following rule.


This is the database head

      bank_name       date px_last       Q_Y p_made p_for p_m p_f
aba.1       ABA 2006-10-24    1.28 p406-q406    406   406   1   1
aba.2       ABA 2006-11-30    1.31 p406-q406    406   406   1   1
aba.3       ABA 2006-10-24    1.29 p406-q107    406   107   1   2
aba.4       ABA 2006-11-30    1.33 p406-q107    406   107   1   2
aba.5       ABA 2006-10-24    1.31 p406-q207    406   207   1   3
aba.6       ABA 2006-11-30    1.35 p406-q207    406   207   1   3


the variable p_f takes values from 1 to 19 in a non regular way.

then I have a vector of 19 elements

> spot$pxlast
 [1] 1.32 1.34 1.35 1.43 1.46 1.58 1.58 1.41 1.40 1.33 1.40 1.46 1.43 1.35 1.22 1.36 1.34 1.42 1.42

I need to create a variable to attach to the data frame which is composed of 11500 rows that takes values
1.32 when p_f==1
1.34 when p_f==2

It seems so easy but I cannot find a way to do it in an efficient way.
Thanks in advance for any help.



Francesca



	[[alternative HTML version deleted]]



More information about the R-help mailing list