[R] Weird problem with trying to change a variable

Peter Flom flom at ndri.org
Fri Jan 16 22:18:48 CET 2004

I have a dataframe called cvar, with two variables (among many others)
called MSA and ACTUP.  Both are numeric.  This was working fine.  Then I
found out that for two MSAs, ACTUP should be 1, not 0.

so I tried

cvar$ACTUP[cvar$MSA == 6840] <- 1
cvar$ACTUP[cvar$MSA == 5360] <- 1

but when I try 

table(cvar$MSA, cvar$ACTUP)

the level of ACTUP for those two MSAs has not changed, and is still 0 

When I try

cvar$MSA  or cvar$ACTUP

I get lists, as I expect.  the MSA list includes 6840 and 5360

when I try

cvar$ACTUP[cvar$MSA == 5360]

I get numeric(0)

Any ideas?  What am I missing on a Friday afternoon?


Peter L. Flom, PhD
Assistant Director, Statistics and Data Analysis Core
Center for Drug Use and HIV Research
National Development and Research Institutes
71 W. 23rd St
New York, NY 10010
(212) 845-4485 (voice)
(917) 438-0894 (fax)

More information about the R-help mailing list