SCM

SCM Repository

[sqlsurvey] Diff of /pkg/sqlsurvey/R/sqlsurvey.R
ViewVC logotype

Diff of /pkg/sqlsurvey/R/sqlsurvey.R

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 36, Mon Nov 4 02:13:51 2013 UTC revision 37, Wed Feb 12 17:35:41 2014 UTC
# Line 367  Line 367 
367    x    x
368  }  }
369    
370  sqlsurvey<-function(id, strata=NULL, weights=NULL, fpc="0",driver,  sqlsurvey<-function(id=NULL, strata=NULL, weights=NULL, fpc="0",driver,
371                         database, table.name=basename(tempfile("_tbl_")),                         database, table.name=basename(tempfile("_tbl_")),
372                         key, check.factors=10,...){                         key, check.factors=10,...){
373    
# Line 384  Line 384 
384      zdata<-make.zdata(db,table.name,factors=check.factors)      zdata<-make.zdata(db,table.name,factors=check.factors)
385    }    }
386    
387      if (is.null(id) || id=="1") {
388          if (is.null(id)) warning("No 'id' given, individual sampling assumed")
389          id<-key
390      }
391    
392    
393    rval<-list(conn=db, table=table.name,    rval<-list(conn=db, table=table.name,
394             id=id, strata=strata,weights=weights,fpc=fpc,             id=id, strata=strata,weights=weights,fpc=fpc,
395             call=sys.call(), zdata=zdata, key=key             call=sys.call(), zdata=zdata, key=key
# Line 885  Line 891 
891    
892         query<-sqlsubst("select %%avgs%%, %%avgsq%%, count(*) as _n_, _fpc_, %%strata%%         query<-sqlsubst("select %%avgs%%, %%avgsq%%, count(*) as _n_, _fpc_, %%strata%%
893                        from                        from
894                              (select %%strata%%, %%sumUs%%, %%fpc%% as _fpc_ from %%basetable%% inner join %%tbl%% using(%%key%%) group by %%units%%,_fpc_)  as r_temp                              (select %%strata%%, %%sumUs%%, avg(%%fpc%%) as _fpc_ from %%basetable%% inner join %%tbl%% using(%%key%%) group by %%units%%)  as r_temp
895                        group by %%strata%%, _fpc_" ,                        group by %%strata%%, _fpc_" ,
896                         list(units=units, strata=strata, sumUs=sumUs, tbl=utable,avgs=avgs,                         list(units=units, strata=strata, sumUs=sumUs, tbl=utable,avgs=avgs,
897                              avgsq=avgsq,fpc=design$fpc[stage], strata=strata,                              avgsq=avgsq,fpc=design$fpc[stage], strata=strata,
# Line 895  Line 901 
901       } else {       } else {
902         query<-sqlsubst("select %%avgs%%, %%avgsq%%, count(*) as _n_,  _fpc_         query<-sqlsubst("select %%avgs%%, %%avgsq%%, count(*) as _n_,  _fpc_
903                        from                        from
904                              (select  %%sumUs%%, %%fpc%% as _fpc_ from %%basetable%% inner join %%tbl%% using(%%key%%) group by %%units%%,_fpc_)  as r_temp" ,                              (select  %%sumUs%%, avg(%%fpc%%) as _fpc_ from %%basetable%% inner join %%tbl%% using(%%key%%) group by %%units%%)  as r_temp group by _fpc_" ,
905                         list(units=units, strata=strata, sumUs=sumUs, tbl=utable,avgs=avgs,                         list(units=units, strata=strata, sumUs=sumUs, tbl=utable,avgs=avgs,
906                              avgsq=avgsq,fpc=design$fpc[stage],                              avgsq=avgsq,fpc=design$fpc[stage],
907                              basetable=tablename, key=design$key                              basetable=tablename, key=design$key

Legend:
Removed from v.36  
changed lines
  Added in v.37

root@r-forge.r-project.org
ViewVC Help
Powered by ViewVC 1.0.0  
Thanks to:
Vienna University of Economics and Business Powered By FusionForge