[R] intermittent errors in [.data.frame

Spencer Graves spencer.graves at structuremonitoring.com
Thu Jul 3 21:52:00 CEST 2014


Hi, Duncan:


On 7/3/2014 12:25 PM, Duncan Murdoch wrote:
> On 03/07/2014 2:55 PM, Spencer Graves wrote:
>>         I get inconsistent results from "[.data.frame".  I've so far 
>> been
>> unable to create a simple, replicable example nor a workaround. With
>> debug, I traced the problem to "rows <- rows[i]", line 131 in
>> "[.data.frame":  In this example, rows = 1:45, and rows[1:3] = 1:3, as
>> we expect.  However with i = 1:3, rows[i] = c(1, 2, 2):
>>
>>
>> Browse[4]> rows[1:3]
>> [1] 1 2 3
>> Browse[4]>i
>> [1] 1 2 3
>> Browse[4]>rows[i]
>> [1] 1 2 2
>>
>>
>>
>>         Absent better suggestions, I currently plan to try to 
>> simplify my
>> example as much as I can while retaining the error. Unfortunately, the
>> search path includes 19 packages (see below), so I expect this not to be
>> easy.  Other suggestions would be welcomed.
>
> Are you computing i using floating point values?  You may have 
> 2.9999999 instead of 3; as an index, it is equivalent to 2, though it 
> will print as 3.
>


       You identified it:


  str(i)
  num [1:3] 1 2 3
Browse[4]> as.integer(i)
[1] 1 2 2


       Thanks so much.
       Spencer

>
> Duncan Murdoch



More information about the R-help mailing list