Skip to content

Weird problem with trying to change a variable

4 messages · Peter Flom, Damon Wischik, Brian Ripley

#
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


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
www.peterflom.com
New York, NY 10010
(212) 845-4485 (voice)
(917) 438-0894 (fax)
#
On Fri, 16 Jan 2004, Peter Flom wrote:

            
`The level'?  You said they were numeric, and it is factors which have 
levels.
Lists?  Do you mean vectors?  Columns of dataframes are not supposed to be 
lists.
So presumably cvar$MSA == 5360 is entirely false, but I would check, and I 
would also check the class of cvar$MSA.

If perchance MSA were a factor, something like the following could be 
happening:
[1] 10000  5360
Levels:  5360 10000
[1] FALSE FALSE
#
Ah. I've been using commands like
x y
1 1, 2, 3 A
2    2, 1 B
3 6, 6, 1 C

This sort of object behaves pretty much as I'd expect it to (using R 1.8.0
for Windows), though I've only made limited use. The x column has mode
list but class AsIs. Is this a legitimate use? 

(The documentation tells me that as.data.frame is a generic method, with
many implementations, including one for AsIs; and that the function I will
accept any object. I haven't looked into the implementation.)

Damon.
#
On Sat, 17 Jan 2004, Damon Wischik wrote:
[Quoting me in reply to something else without the context not 
attribution.]
Yes.  That is not a `bare' list, but a class with a specific method.
All you need is for the length to match.  It is possible to get bare lists
into data frames, but as.data.frame.list inserts each column separately
and if you do circumvent that (and I don't mean by I()) some strange
things can happen.  We don't guarantee not to break what currently works
in that area, either.