[R] understanding behavior of "merge"

David Winsemius dwinsemius at comcast.net
Fri Apr 30 04:00:04 CEST 2010

On Apr 29, 2010, at 7:26 PM, Chris__ Barker wrote:

> I'm trying to bootstrap resample from a repeated measures dataset. I  
> sample
> a vector of "ID"'s from my dataframe with replacement.
> Then I merge this back with my dataframe.
> I'm re-sampling subjects in the dataset rather than rows of the data.
> I thought I could use the left/right join features of the merge to  
> select
> the records I want from the dataframe (mydataframe), like this.
> boot.sample <-  merge(  id.boot.draw,mydataframe, by=c("ID") ,  
> all.x=TRUE )
> when I do that, the correct records are selected from "mydataframe"  
> but the
> values for all the variables, other than the matching variable are  
> now "NA".

Cannot say. No data provided. But have you considered drawing your  
sample from rowsamp <- row.names(mydataframe) ,   and then just  
working with:

boot.samp <-  mydataframe[rowsamp,  ]

> My other option is to right a for loop, which I would hope to avoid.
> Thanks in advance for any suggestions
David Winsemius, MD
West Hartford, CT

More information about the R-help mailing list