[R] non permanent change of vector values
    Federico Calboli 
    f.calboli at imperial.ac.uk
       
    Wed Jun 20 12:46:56 CEST 2007
    
    
  
Hi All,
I have the following problem: I have a vector
x = rep(0,15)
x[1:2] = 1
x
  [1] 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0
I need to be able to call that vector 'x' so that if condition 'A' is true, only 
the first value is kept 'as is' and all the others are put to 0
if(A == T)
function(x) with x returning 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
and if 'A' is false the second value is kept 'as is' and all the others are put to 0
if(A == F)
function(x) with x returning 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0
BUT, and that's the rub, I need x to changed in a *non permanent* way, so that 
at the end x is still
x
  [1] 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0
(that is because condition 'A' might be called again and could be different in 
it's T/F state from previous calls).
Any ideas?
Cheers,
Fede
-- 
Federico C. F. Calboli
Department of Epidemiology and Public Health
Imperial College, St Mary's Campus
Norfolk Place, London W2 1PG
Tel  +44 (0)20 7594 1602     Fax (+44) 020 7594 3193
f.calboli [.a.t] imperial.ac.uk
f.calboli [.a.t] gmail.com
    
    
More information about the R-help
mailing list