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
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
>
> #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.
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
4 matches
Mail list logo