# lapply and svyratio

#### jfca283

##### Member
Hello,
I need to compute some ratios using a survey.
I manage to calculate regional totals after especifying a list of variables (regions).
Regions are dummies from 1 to 17, taking the value of 1 if the observation belongs to the region1.
This code works. It computes totals by regions using the variable s3
Code:
lapply( regions , function( z ) svyby( as.formula( paste0( "~" , z ) ) , by = ~s3, design=ddd, svytotal , vartype = 'cv',na.rm=T ) )
When I try to perform the same task with svyratio, the code computes everything wrong.
Here I'm pretending to obtain the ratio s3/s1 for each regional dummy:
Code:
lapply( regions , function( z ) svyby( as.formula( paste0( "~" , z ) ) , by = ~s3, denominator=~s1,  design=ddd, svyratio, vartype = 'cv',na.rm=T ) )
I know It's wrong because I wrote a code using a loop for computing the task.

These are the totals using lappy for the 17nth region: 0.0683...=617.487/9031544->That's ok

Using lapply for computing the same ratio in the 17nth region, I get this : I have no idea the reason for this output.
Thanks for your time, interest and replies.