Skip to content
Prev 258758 / 398502 Next

Simple loop

It is actually possible and preferable to do this with no loops.
Assuming your data is in a dataframe called dat:

idx <- with(dat, Site == 1 & Prof == 1)
dat <- within(dat, { new = H - ifelse(Site == 1 & Prof == 1,
min(H[idx]), min(H[!idx])) })
dat

which also serves to illuminate the difference between with and within
as a bonus.

HTH,
Jon
On Tue, May 3, 2011 at 11:44 AM, Woida71 <w.gostner at ipp.bz.it> wrote: