Hello to everyone, this is my first post. I used to be an average+ SAS programmer (I'm still do). I am only one week old with R. Maybe this question sound elemental for you, bit for me...

I wrote this code:

library(rlang)

regi <- c(1,2,3,4,5,6)

vQUINT <- list(parse_expr("quintilH1"), parse_expr("quintilH2"), parse_expr("quintilH3"), parse_expr("quintilH4"), parse_expr("quintilH5"), parse_expr("quintilH6"))

q1H <- quintilesH$H_20

q2H <- quintilesH$H_40

q3H <- quintilesH$H_60

q4H <- quintilesH$H_80

#REGIONES

quintilH_AUX <- subset(persona, vFINHOG==1 & ingtotp_P>0) %>%

select (nprvnc, nups, narea, nordn, nvvnd, nhogar, ingtotp_P, expan, region, vFINHOG)

for (i in regi){

quintilH_AUX <- quintilH_AUX %>%

mutate(vQUINT[i]=case_when(region==i & ingtotp_P <= q1H [i+1] ~1)) %>%

mutate(vQUINT[i]=case_when(region==i & ingtotp_P > q1H [i+1] & ingtotp_P <= q2H [i+1] ~2, TRUE ~ vQUINT[i])) %>%

mutate(vQUINT[i]=case_when(region==i & ingtotp_P > q2H [i+1] & ingtotp_P <= q3H [i+1] ~3, TRUE ~ vQUINT[i])) %>%

mutate(vQUINT[i]=case_when(region==i & ingtotp_P > q3H [i+1] & ingtotp_P <= q4H [i+1] ~4, TRUE ~ vQUINT[i])) %>%

mutate(vQUINT[i]=case_when(region==i & ingtotp_P > q4H [i+1] ~5, TRUE ~ i))

}

I cant make this loop works. The only problem I found is when i try to create a column with mutate using iteration.

Thanks in advance!