loops for warning number of items to replace is not a multiple of replacement length

Hello community, I try to replace values ​​in one variable from another, using a for loop. and it gives me a warning that I don't understand, (number of items to replace is not a multiple of replacement length) the code I'm using is the following:

attach(ENCFT_20191)
table(pension_ext_moneda,periodo)

       p_s4d21_1 <-  ifelse(pension_ext==1 , pension_ext_monto, NA )
       
       for(i in 1:length(pension_ext_moneda)) {
         if(pension_ext_moneda[i]=="EUR"  & periodo[i] == 201901) p_s4d21_1[i]= pension_ext_monto*tcR[2,6] else
           if (pension_ext_moneda[i]=="USD"  & periodo[i] == 201901)  p_s4d21_1[i]= pension_ext_monto*tcR[3,6] else
             if (pension_ext_moneda[i]=="REAL" & periodo[i] == 201901) p_s4d21_1[i] = pension_ext_monto*tcR[4,6]	
       }

Hi!

To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.