[R] pairing data using combn with criteria

David Winsemius dwinsemius at comcast.net
Fri Nov 16 21:23:18 CET 2012


On Nov 16, 2012, at 6:58 AM, bjmjarrett wrote:

> Dear All,
> 
> I have a dataframe made up of individual beetles consisting of individual
> number, family number, mother's family number, father's family number, and
> sex of the beetle.  I would like to pair up the individuals for breeding.  I
> would, however, like to avoid breeding beetles of the same sex (obviously),
> the same family, and with the same mother's family or father's family, to
> avoid inbreeding. 
> 
> The pairs of the beetles can be done with the function combn(individual, 2). 
> I have been trying to use the FUN argument of combn by reducing the options
> for combn for each individual by negating the rows that share the same sex,
> family, and parents' families, but I have had no success.
> 
> Is there an easy way to package all of this into a function for the combn
> FUN argument, or is there an alternative way of doing this?

See if this helps:

 combn( 1:5, 2, FUN = function(b){ 
                 if (max (b) < 4 ) { b } else { c(NA,NA) } } )
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,]    1    1   NA   NA    2   NA   NA   NA   NA    NA
[2,]    2    3   NA   NA    3   NA   NA   NA   NA    NA

-- 

David Winsemius, MD
Alameda, CA, USA




More information about the R-help mailing list