我L在R的踪迹是:
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
Run Code Online (Sandbox Code Playgroud)
我尝试使用?L没有成功.
到底是x[<n>L]什么?任何进一步使用它的例子?
我在具有400GB RAM的64位Ubuntu环境中运行64位R 3.1,在处理大型矩阵时遇到了一个奇怪的限制.
我有一个名为A的数字矩阵,即4000行乘950,000列.当我尝试访问其中的任何元素时,我收到以下错误:
Error: long vectors not supported yet: subset.c:733
Run Code Online (Sandbox Code Playgroud)
虽然我的矩阵是通过via读取的scan,但您可以使用以下代码进行复制
test <- matrix(1,4000,900000) #no error
test[1,1] #error
Run Code Online (Sandbox Code Playgroud)
我的谷歌搜索显示这是R 3.0之前的常见错误消息,其中大小为2 ^ 31-1的向量是限制.但是,鉴于我的环境,情况并非如此.
我不应该为这种矩阵使用原生矩阵类型吗?
在 R 源代码中,大多数(但不是全部)函数使用整数值作为常量:
colnames <- function(x, do.NULL = TRUE, prefix = "col")
{
if(is.data.frame(x) && do.NULL)
return(names(x))
dn <- dimnames(x)
if(!is.null(dn[[2L]]))
dn[[2L]]
else {
nc <- NCOL(x)
if(do.NULL) NULL
else if(nc > 0L) paste0(prefix, seq_len(nc))
else character()
}
}
Run Code Online (Sandbox Code Playgroud)
R语言定义说:
在大多数情况下,整数和数值之间的差异并不重要,因为 R 在使用数字时会做正确的事情。然而,有时我们想显式地为常量创建一个整数值。
问题是关于良好实践和基本原理,而不是关于“L”符号本身、整数类和数字类之间的差异或比较数字。
我正在研究R编程的入门,并注意到一个轻微的异常:
x <- c(2,1,1,5) 生成一个类型的向量 numy <- c(1:5) 生成一个类型的向量 intz <- c(1.5,2.3) 生成一个类型的向量 num为什么会这样?什么是基本数据类型R:是int或是它num?如果向量中的一个元素是a float,那么向量的类型会变成float或者是其他东西会发生什么?当向量中的所有元素都是float- 为什么它仍然num在那种情况下会发生什么?
我的问题是如何利用 iMac 的多个核心来使 gganimate 运行得更快。还有另一个问题(更多链接在下面)询问同样的事情\xe2\x80\x94我的问题是关于这个问题的答案:加速 gganimate Rendering。
\n在该答案中,Roman 和 mhovd 指出了此GitHub 评论中的一个示例(另请参阅此 GitHub 帖子):
\nlibrary(gganimate)\nlibrary(future)\n\nanim <- ggplot(mtcars, aes(mpg, disp)) +\n transition_states(gear, transition_length = 2, state_length = 1) +\n enter_fade() +\n exit_fade()\n\nfuture::plan("sequential") ## default\nt0 <- system.time(animate(anim))\nprint(t0)\n\nfuture::plan("multiprocess", workers = 4L)\nt1 <- system.time(animate(anim))\nprint(t1)\nRun Code Online (Sandbox Code Playgroud)\n我已经尝试过这个,但得到的时间彼此非常接近:
\n user system elapsed \n1.0041475 0.9775679 0.9995509 \nRun Code Online (Sandbox Code Playgroud)\n除了这段代码之外,我还需要做些什么吗?根据上述 StackOverflow 答案或 GitHub 页面,我无法判断这段代码是否应该按原样工作,或者是否在幕后进行了其他修改。
\n如果有帮助的话,我正在使用配备 8 核 Intel 处理器的 iMac。我也在 R 中运行它,因为 RStudio 说了一些关于它不支持多核的内容。
\n另请注意,我的问题也广泛涉及这三个过去的问题:
\n …假设我们有一个向量:
v <- c(0,0,0,1,0,0,0,1,1,1,0,0)
Run Code Online (Sandbox Code Playgroud)
预期产量:
v_index <- c(5,6,7)
Run Code Online (Sandbox Code Playgroud)
v总是开始和结束0.在两个1s 之间只有一个零簇的可能性.
看似简单,无法理解我的头脑......