Re: [R] vectorising ifelse()

From: Kevin Bartz <>
Date: Fri 22 Jul 2005 - 11:14:03 EST

The code as you provided it is a bit unusual. In the second assignment, you're using "drow[i]>0" as an index into "new," but ifelse has already found that condition to be true, which means what you wrote is just the same as saying new[1,zappo[i]].

Also, if zappo and zappo are vectors of probabilities, why are they being used as indices into new? Indices are supposed to be integers or T/Fs.

It would be nice if you could provide some example data. I'm sure there's a way to vectorize it, but I'm struggling to get my head around the Zippos, zappos and haplos.


-----Original Message-----
[] On Behalf Of Federico Calboli Sent: Thursday, July 21, 2005 4:44 PM
To: r-help
Subject: [R] vectorising ifelse()

Hi All,

is there any chance of vectorising the two ifelse() statements in the following code:

for(i in gp){

   new[i,1] = ifelse(srow[i]>0, new[srow[i],zippo[i]], sample(1:100, 1,
prob =Y1, rep = T))
   new[i,2] = ifelse(drow[i]>0, new[drow[i]>0,zappo[i]], sample(1:100,
1, prob =Y1, rep = T))

Where I am forced to check if the value of drow and srow are >0 for each line... in practical terms, I am attributing haplotypes to a pedigree, so I have to give the haplotypes to the parents before I give them to the offspring. The vectors *zippo* and *zappo* are the chances of getting one or the other hap from the sire and dam respectively. *gp* is the vectors of non-ancestral animals. *new* is a two col matrix where the haps are stored.



Federico C. F. Calboli
Department of Epidemiology and Public Health
Imperial College, St Mary's Campus
Norfolk Place, London W2 1PG

Tel  +44 (0)20 7594 1602     Fax (+44) 020 7594 3193

f.calboli [.a.t]
f.calboli [.a.t]

______________________________________________ mailing list PLEASE do read the posting guide!
______________________________________________ mailing list PLEASE do read the posting guide!
Received on Fri Jul 22 11:20:12 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:33:55 EST