Skip to content
Back to formatted view

Raw Message

Message-ID: <3E8A9362.2090100@statistik.uni-dortmund.de>
Date: 2003-04-02T07:38:10Z
From: Uwe Ligges
Subject: vectorize an expression
In-Reply-To: <FFE02AF26875734B82A728403821CB2EFB043A@asp-ri.riverside.csiro.au>

Simon.Gatehouse at csiro.au wrote:
> Dear listers,
> I'm having a bad R day.  I just can't think of the vectorized equivalent of:
> 
> for (ii in 1:n)   aa[ii]  =  bb[ii,cc[ii]]
> 
> Any suggestion received with embarrassment and gratitude


a <- b[cbind(1:n, cc[1:n])]

Uwe Ligges


> Simon Gatehouse                                  
> CSIRO Exploration and Mining,
> Newbigin Close off Julius Ave
> North Ryde, NSW
>  
> Mail:      PO Box 136, North Ryde
>            NSW 1670, Australia
> Phone:     61 (2) 9490 8677
> Fax:       61 (2) 9490 8921
> Mobile:    61  0407 130 635 
> E-mail:    simon.gatehouse at csiro.au
> Web Page:  http://www.csiro.au/
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help