im trying to loop mi df using a for based in a vector whit the names of the columns what i want to loop, the code is:
percep <- clv_zmvm #unique key column (CVEGEO)
#the columns from E1617_zmvm
vect_var <- c("ts18","ts19", "ts20", "ts21", "ts22", "ts23", "ts24")
for (x in vect_var){
v <- E1617_zmvm %>% group_by(CVEGEO) %>% filter(x>=2) %>% summarise(n())
names(v)=c("CVEGEO", x) #rename n() column in v
percep <- percep %>% left_join(v) #join the v result
}
The code works, the problem is all the columns have the same values and that isnt correct.