Skip to content
Prev 2496 / 398506 Next

Question on the idiom: start <- coef; start[fit$pivot] <- coef

On Fri, 30 Apr 1999, Barnet Wagman wrote:

            
I wouldn't try looking in the source code for something as fundamental as
this. It is simple:

b[c(1,3,4,2,5)] <- a

replaces the first element specified on the lhs by the first specified on
the rhs, etc. So it means	

b[1] <- 100; b[3] <- 200; b[4] <- 300; b[2] <- 400; b[5] <- 500

and this permuting (or reversing a permutation) is the key idea.

Understanding indexing in S is one key to unlocking its power: section 2.8
of Venables & Ripley might be a good place to look for a full description.