Skip to content
Prev 201333 / 398503 Next

non-intuitive behaviour after type conversion

When you attach() something, it loads it into memory and there it 
stays. It is not a link, reference, or pointer to the original. 
Changing the original (the version in the dataframe), which is what 
you did, does not change the attached copy in memory. In essence, you 
did a type conversion on one copy, but afterwards started looking at 
the other copy.

See also an interjected comments below.

-Don
At 8:54 AM +0000 11/23/09, Alan Kelly wrote:
Right.
   find('t1stvisit')
will show you there are two of them, and where in memory they are located.
If you type
    t1stvisit
at the prompt, you always get the first one. The one in the attached 
dataframe is the second one. Use the
   search()
function to show you the different locations in memory where objects 
can be found.

When you did the attach(), did you get a message like:
The following object(s) are masked _by_ .GlobalEnv :

          x

(yours would have referred to your variables, not the "x" in my example).
That message tells you you have two variables of the same name, 
stored in two different locations in the search path.

As a general rule, it's just plain confusing to have more than one 
object of the same name in more than one location. In your situation, 
I would get rid of the one that's not in the dataframe. But even 
then, if you change it in the dataframe you'll still need to detach 
and re-attach the dataframe, so using attach() is probably not the 
best choice in the long run. Maybe the with() function would meet 
your needs.