gpt4 book ai didi

r - 在R中澄清L

转载 作者:行者123 更新时间:2023-12-03 10:25:56 24 4
gpt4 key购买 nike

我在R中的L上的足迹是:

c<-1:10
c
# [1] 1 2 3 4 5 6 7 8 9 10
c[-1]
# [1] 2 3 4 5 6 7 8 9 10
c[-2]
# [1] 1 3 4 5 6 7 8 9 10
c[-1L]
# [1] 2 3 4 5 6 7 8 9 10
c[-2L]
# [1] 1 3 4 5 6 7 8 9 10

我尝试使用 ?L失败。
x[<n>L]的确是什么?有进一步使用示例吗?

最佳答案

该答案是以上评论的总结。它基本上只是指向各种帮助文本的指针,但是从OP尝试使用?L可以明显看出,查找相关的帮助文本并不总是那么容易。我期待在L中找到有关?as.integer的信息,但没有。希望这个答案比一堆评论有用。

  • R languagedefinition
    您会发现:“我们可以使用L后缀来限定任何数字
    目的是使其成为显式整数”
  • 来自?NumericConstants:“[...]所有其他数字常量开始
    带有数字或句点,并且可以是十进制或十六进制
    常量(可选)后跟L

    “紧随其后的L的数字常量被视为
    整数(如果可能)(如果包含
    “。”)。

    “您可以将“0x”前缀与“L”后缀结合使用。
  • 您可能还会发现检查浮点示例很有用
    与“重新介绍的两种”中的整数
    here
    “在数字后面加上大写的L(如“long”),以使R创建为
    整数”。
  • 并非专门针对L,但始终与浮点数相关
    vs.整数的上下文是FAQ7.31:“为什么R认为这些数字不相等?”。


  • 讨论L效率的主题:

    R-help上的线程,其他人很难找到有关 L的文档,并可能在效率方面解释了为什么字母 L以及为什么 Las.integer的可能关系。
  • Difference between 10 and 10L

    第一威廉·邓拉普(William Dunlap):

    Why not 10I for integer? Perhaps because "I" and "l" look too similar, perhaps because "i" and "I" sound too similar. The "L" does not mean "long": integers are 4 bytes long.



    然后是Brian Ripley:

    Actually it does: this notation dates from the C language on 16-bit computers where integers were 16-bits and longs were 32-bit (and R has no 'long' type).

    The author of this in R never explained why he chose the notation, but it is shorter than as.integer(10), and more efficient as the coercion is done at parse time.

  • The L Word
    讨论不同情况下的效率,并提供一些基准测试。
  • R history: Why 'L; in suffix character ‘L’ for integer constants?
  • 更多讨论here
  • 关于r - 在R中澄清L,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22191324/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com