[R] Im(z) <-

Robin Hankin r.hankin at soc.soton.ac.uk
Tue Dec 21 10:01:32 CET 2004


Hello everybody

If

R> a <- 1i+(1:10)

I would like to say

R> Im(a) <- 1:10
R> a
  [1]  1+ 1i  2+ 2i  3+ 3i  4+ 4i  5+ 5i  6+ 6i  7+ 7i  8+ 8i  9+ 9i 
10+10i


But there does not seem to be a "Im<-" function.

How about this:

"Im<-" <- function(x,value){
   if(is.complex(value)){stop("value must be real")}
   if(all(value==0)){
     return(Re(x))
   } else {
     return(Re(x)+1i*value)
   }
}



comments anyone?  can I infer that the above is a bad idea from the
absence of a "Im<-"() function in R?



--
Robin Hankin
Uncertainty Analyst
Southampton Oceanography Centre
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743




More information about the R-help mailing list