测量执行时间的R是否有标准化的方法?
显然我可以system.time在执行之前和之后采取,然后采取其中的差异,但我想知道是否有一些标准化的方式或功能(想要不发明轮子).
我似乎记得我曾经使用过如下的东西:
somesysfunction("myfunction(with,arguments)")
> Start time : 2001-01-01 00:00:00 # output of somesysfunction
> "Result" "of" "myfunction" # output of myfunction
> End time : 2001-01-01 00:00:10 # output of somesysfunction
> Total Execution time : 10 seconds # output of somesysfunction
Run Code Online (Sandbox Code Playgroud) 我只是寻找B1(newx)线性模型系数的值,而不是名称.我只想要0.5值.我不想要名字"newx".
newx <- c(0.5,1.5.2.5)
newy <- c(2,3,4)
out <- lm(newy ~ newx)
Run Code Online (Sandbox Code Playgroud)
out 好像:
Call:
lm(formula = newy ~ newx)
Coefficients:
(Intercept) newx
1.5 1.0
Run Code Online (Sandbox Code Playgroud)
我到了这里 但现在我被卡住了.
out$coefficients["newx"]
newx
1.0
Run Code Online (Sandbox Code Playgroud) 这似乎很简单,但我找不到答案.我使用cbind()组合了两个向量.
> first = c(1:5)
> second = c(6:10)
> values = cbind(first,second)
Run Code Online (Sandbox Code Playgroud)
当我想使用值[1,2]检索单个元素时,除了实际元素之外,我总是得到列名.
> values[1,2]
second
6
Run Code Online (Sandbox Code Playgroud)
如何在没有列名的情况下获取值?
我知道我可以删除矩阵中的列名,如下文所示:如何从R中的矩阵中删除列名?但是我怎样才能保留矩阵,只得到我想要的值?