Is it okay to use floating-point numbers as indices or when creating factors in R?

前端 未结 2 566
广开言路
广开言路 2021-01-19 13:06

Is it okay to use floating-point numbers as indices or when creating factors in R?

I don\'t mean numbers with decimal parts; that would clearly be odd, but instead n

2条回答
  •  一生所求
    2021-01-19 13:45

    Constructs such as 1:3 are really integers:

    > class(1:3)
    [1] "integer"
    

    Using a float as an index entails apparently some truncation:

    > foo <- 1:3
    > foo
    [1] 1 2 3
    > foo[1.0]
    [1] 1
    > foo[1.5]
    [1] 1
    

提交回复
热议问题