Robin Hankin wrote:
Hi

I have a little function that takes a vector v and an integer i. I want to manipulate
v[-i] (to give v.new, say) and
then put (unmanipulated) v[i] back into the appropriate place. For example,



f <- function(v,i){ v.new <- v[-i]+10 return(c(v.new[1:(i-1)],v[i],v.new[i:length(v.new)])) }

Take the complement of 'i', and change the values of v in place?

f <- function(v,i){
  v[-i] <- v[-i]+10
  v
}

 Now i can be an integer or a vector of integers or true/falses.

Baz

______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to