df <- data.frame(rep=c(0.2,0.3,0.2),
lon=c(35,36,37),
lat=c(-90,-91,-92),
v1=c(10,0,8),
v2=c(3,4,5),
v3=c(9,20,4))
v <- as.vector("numeric")
for(i in 1:3) v[i] <- sum(df$rep[df[,i+3]!=0])
solved Conditional summation in r