[R] How to use Subpopulation data?

Bernardo Rangel Tura tura at centroin.com.br
Fri Oct 2 11:08:00 CEST 2009


On Fri, 2009-10-02 at 00:42 +0000, KABELI MEFANE wrote:
> Thanks
> 
> But it seems like you don't get my problem.Do you mean that there is something wrong with the code as it seems like what you are doing is suggesting different ways to write a code. 
> 
> Will i get to use the variable that have been name previously like if i want to calculate the standard deviation of stratum hypermarket in a sample not population, the first start is to check if it would help me is to check the length() of different levels if it is not same as that of the original data
> 
> Best Regards
> 
> I rest my case, i might dream it

Sorry

I don't understand your problem early.

In your case you have 2 data.frames: sampleframe and sample.strat so you
need show to R where calculate sd or length or summary


set.seed(1)# only to make this example don't use in your code
stra<-strata(sampleframe,c("type"),size=c(20,80,200,300,400),method="srswor")
sample.strat<-getdata(sampleframe,stra)

length of value in sampleframe where type is Hypermarket:
> length(sampleframet$value[sampleframe$type=="Hypermarket"]) 
[1] 100

SD of value in sampleframe where type is Hypermarket:
> sd(sampleframe$value[sampleframet$type=="Hypermarket"])
[1] 4586.854

length of value in sample.strat where type is Hypermarket:
> length(sample.strat$value[sample.strat$type=="Hypermarket"] )
[1] 20

SD of value in sample.strat where type is Hypermarket:
> sd(sample.strat$value[sample.strat$type=="Hypermarket"] )
[1] 4679.336


-- 
Bernardo Rangel Tura, M.D,MPH,Ph.D
National Institute of Cardiology
Brazil




More information about the R-help mailing list