Re: [R] Assigning value to a vector from within a function

2010-10-06 Thread David Winsemius
On Oct 6, 2010, at 1:31 PM, Andrew Barr wrote: Hi all, I am having trouble assigning a value within a vector using a variable defined within a function. I suspect this has something to do with namespaces but I cannot figure it out. Please reply directly to me if you can help. ###begin co

Re: [R] Assigning value to a vector from within a function

2010-10-06 Thread Henrique Dallazuanna
See the replace function: index <- 3 test <- replace(test, index, 20) On Wed, Oct 6, 2010 at 2:31 PM, Andrew Barr wrote: > Hi all, > > I am having trouble assigning a value within a vector using a variable > defined within a function. I suspect this has something to do with > namespaces but I

Re: [R] Assigning value to a vector from within a function

2010-10-06 Thread Peter Langfelder
> > #another simple function to update the value in a vector > update<-function(index){ > test[index]<- 20 > } > update(2) > test > #The update() function silently fails to accomplish the update Replace the '<-' by '<<-' and you'll be good to go if you call the function from a global environment.

[R] Assigning value to a vector from within a function

2010-10-06 Thread Andrew Barr
Hi all, I am having trouble assigning a value within a vector using a variable defined within a function. I suspect this has something to do with namespaces but I cannot figure it out. Please reply directly to me if you can help. ###begin code #simple vector test<-c(4,5,6) #simple function to