[R] Combining Data Sets w/ Weights

David Winsemius dwinsemius at comcast.net
Fri Sep 17 19:03:28 CEST 2010


On Sep 17, 2010, at 11:15 AM, btpagano wrote:

>
> Here it is...
>
>> str(Males$BMXHT)
> num [1:2801] 168 161 180 182 169 ...
>> str(Females$BMXHT)
> num [1:3440] 162 159 164 165 159 ...
>> str(Males$yourWeight)
> num [1:2801] 1148 788 10298 25115 8691 ...
>> str(Females$myWeight)
> num [1:3440] 9169 4964 2608 2806 907 ...
>
> I want to combine Males$BMXHT with Females$BMXHT.

If you have already gone to the trouble of splitting the data into  
separate male and female dataset (an entirely unnecessary and probably  
wasteful step I might add) then you can recombine particular vectors  
with the c() function ("c" for concatenate).

>  I also want to combine
> Males$yourWeight and Females$myWeight in a similar way so that I can  
> use the
> wtd.quantile() command in the following way:
>
> wtd.quantile(Everybody$BMXHT, weights=ourWeight, 0.05)

I hope you are using the weights argument correctly. You need to be  
clear about whether these are: sampling weights, frequency weights  
(which I believe is the correct form for this particular function) or  
weights in pounds (and that would make no sense but the HT and Weight  
terminology made me ask).

wtd.quantile(  c(Males$BMXHT,Females$BMXHT) ,
              weights= c(Males$yourWeight, Females$myWeight), 0.05)

If those values had been in the same object with a sex variable, there  
would have been much more efficient methods available.

>
> I know that this might seem like some elementary stuff, but I'm not  
> too
> familiar with R yet.  I hope to become much better in the future.

I fear that you have some unlearning of inefficient statistical  
practices that were taught you in Minitab classes.

>
> Thanks for all of your help,
>
> Brian
>
> -- 
> View this message in context: http://r.789695.n4.nabble.com/Combining-Data-Sets-w-Weights-tp2543167p2543995.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list