[R] Scope and sapply

Sarah Goslee sarah.goslee at gmail.com
Sun Jun 13 03:26:39 CEST 2010


Hi,

On Sat, Jun 12, 2010 at 9:22 PM, Worik R <worikr at gmail.com> wrote:
> I am puzzled by the scope rules that apply with sapply.
>
> If I want to modify a vector with sapply I tried...
>
> N <- 10
> vec <- vector(mode="numeric", length=N)
> test <- function(i){
>  vec[i] <- i
> }
> sapply(1:N, test)
> vec

You didn't assign the results of sapply to anything, and you didn't
assign anything new to vec.

What did you expect to happen?

-- 
Sarah Goslee
http://www.functionaldiversity.org



More information about the R-help mailing list