[R] paired samples, matching rows, merge()

Cecilia Carmo cecilia.carmo at ua.pt
Fri Aug 20 15:59:36 CEST 2010


The last one worked! The other one, not.
Thank you very much!

Another question about merge(): sometimes I'm merging two 
dataframes and the merged dataframe has much more rows 
than the two merged? I think this should not happen,does 
it?

Cecília


Em Fri, 20 Aug 2010 09:37:26 -0400
  Gabor Grothendieck <ggrothendieck at gmail.com> escreveu:
> On Fri, Aug 20, 2010 at 9:33 AM, Gabor Grothendieck
> <ggrothendieck at gmail.com> wrote:
>> On Fri, Aug 20, 2010 at 9:27 AM, Cecilia Carmo 
>><cecilia.carmo at ua.pt> wrote:
>>> It wasn't the merge command. It doesn't create the 
>>>variable x3.
>>>
>>> Cecília
>>>
>>>
>>
>> How about:
>>
>> x$k3 <- with(x, unlist(tapply(k1, k1, seq_along)))
>> y$k3 <- with(y, unlist(tapply(k1, k1, seq_along)))
>>
> 
> And here is a second one in case that one overflows as 
>well:
> 
> x$k3 <- with(x, seq_along(k1) - match(k1, k1) + 1)
> y$k3 <- with(y, seq_along(k1) - match(k1, k1) + 1)
> 
> Note that this one assumes that the data frame is sorted 
>by k1 which
> in your example it is.



More information about the R-help mailing list