澄清R中的L [英] Clarification of L in R
问题描述
我在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]
的确是什么?有进一步使用它的例子吗?
What indeed is x[<n>L]
? Any example for further usage of it?
推荐答案
此答案是以上评论的摘要.它基本上只是指向各种帮助文本的指针,但是从OP对?L
的尝试中可以明显看出,找到相关的帮助文本并不总是那么容易.我期望在?as.integer
中找到有关L
的信息,但没有.希望这个答案比一堆评论有用.
This answer is a summary of the comments above. It is basically just pointers to various help texts, but as evident from OP's attempt with ?L
, it is not always easy to find the relevant help text. I was expecting to find something about L
in ?as.integer
, but no. Hopefully this answer is more useful than a pile of comments.
- 使用 R语言
定义
您会发现:我们可以使用
L
后缀来限定任何数字 旨在使其成为一个显式整数" -
来自
?NumericConstants
:"[...]所有其他数字常量开始 带有数字或句点,并且可以是十进制或十六进制 常量(可选),后跟L
"
- In the R language
definition
you will find: "We can use the
L
suffix to qualify any number with the intent of making it an explicit integer" From
?NumericConstants
: "[...] All other numeric constants start with a digit or period and are either a decimal or hexadecimal constant optionally followed byL
"
"紧随其后的数字常量L
被视为
整数(如果可能)(如果包含
.")."
"An numeric constant immediately followed by L
is regarded as an
integer number when possible (and with a warning if it contains a
".")."
您可以将前缀"0x
"与后缀"L
"结合使用.
"You can combine the "0x
" prefix with the "L
" suffix".
有关有关L
效率的讨论的主题:
Threads with discussions about the efficiency of L
:
R-help上的线程,其他人很难找到有关L
的文档,并可能对字母L
的原因以及为什么L
vs as.integer
的效率进行了解释.
Threads on R-help where others have struggled to find documentation about L
, with a possible explanation of why the letter L
, and why L
vs as.integer
in terms of efficiency.
第一位威廉·邓拉普(William Dunlap):
First William Dunlap:
为什么
10I
不是整数?可能是因为"I
"和"l
"看起来太相似,也许是因为"i
"和"I
"听起来太相似了. "L
"并不表示"long":整数为4个字节长.
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):
Then Brian Ripley:
实际上是这样的:此表示法起源于16位C语言 整数为16位而long为32位的计算机(R 没有"long"类型).
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).
R中这个的作者从未解释过为什么他选择了这种符号,但是
它比as.integer(10)
短,并且效率更高,因为强制是
在解析时完成.
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.
L字
通过基准测试讨论不同情况下的效率.
The L Word
Discussion about the efficiency in different situations, with some benchmarkings.
更多讨论 此处 .
这篇关于澄清R中的L的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!