Re: [R] Scope and sapply

From: Sarah Goslee <sarah.goslee_at_gmail.com>
Date: Sat, 12 Jun 2010 21:26:39 -0400

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

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Sun 13 Jun 2010 - 01:28:17 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 13 Jun 2010 - 05:30:29 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive