Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat makes these two R data frames not identical?
    primarykey
    data
    text
    <p>I have two small data frames, <code>this_tx</code> and <code>last_tx</code>. They are, in every way that I can tell, completely identical. <code>this_tx</code> == <code>last_tx</code> results in a frame of identical dimensions, all <code>TRUE</code>. <code>this_tx %in% last_tx</code>, two <code>TRUEs</code>. Inspected visually, clearly identical. But when I call</p> <p><code>identical(this_tx, last_tx)</code></p> <p>I get a <code>FALSE</code>. Hilariously, even</p> <p><code>identical(str(this_tx), str(last_tx))</code></p> <p>will return a <code>TRUE</code>. If I set <code>this_tx &lt;- last_tx</code>, I'll get a <code>TRUE</code>.</p> <p>What is going on? I don't have the deepest understanding of R's internal mechanics, but I can't find a single difference between the two data frames. If it's relevant, the two variables in the frames are both factors - same levels, same numeric coding for the levels, both just subsets of the same original data frame. Converting them to character vectors doesn't help.</p> <p>Background (because I wouldn't mind help on this, either): I have records of drug treatments given to patients. Each treatment record essentially specifies a person and a date. A second table has a record for each drug and dose given during a particular treatment (usually, a few drugs are given each treatment). I'm trying to identify contiguous periods during which the person was taking the same combinations of drugs at the same doses.</p> <p>The best plan I've come up with is to check the treatments chronologically. If the combination of drugs and doses for treatment[i] is identical to the combination at treatment[i-1], then treatment[i] is a part of the same phase as treatment[i-1]. Of course, if I can't compare drug/dose combinations, that's right out.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload