我试图用来Sys.time获取两点之间经过的时间。但是,它并没有以我喜欢的方式输出。
现在看起来是这样的:
a <- Sys.time
...running stuff between these two points...
b <- Sys.time
c <- b - a
c
Time difference of 1.00558 hours
Run Code Online (Sandbox Code Playgroud)
我只想要数字和单位。我知道要得到我能做的数字:
c[[1]]
Run Code Online (Sandbox Code Playgroud)
然而,有时结果c可以给我几秒钟或几分钟。我只想要其中有数字且单位为小时的实例。有谁知道使用 Sys.time() (或任何替代方法)我会得到类似以下内容的方法:
if (units == "hours")
{
if (number => 1)
{
#do something
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个二项式检验的结果,它看起来像这样:
data: x and n
number of successes = 0, number of trials = 7, p-value = 0.01563
alternative hypothesis: true probability of success is not equal to 0.5
95 percent confidence interval:
0.0000000 0.4096164
sample estimates:
probability of success
0
Run Code Online (Sandbox Code Playgroud)
我只想知道如何提取R中的p值。我尝试了grep和pmatch,但它们似乎需要表或向量。
是否可以相互交换两个相邻的行,然后移动到接下来的两行,并将它们各自的行交换在一起?即在行1中交换col1值,在row2中交换col 1值; 在行87中交换col 1700值,在行88中交换col 1700值.
样本数据:
col1 col2
row1 a b
row2 b b
row3 c a
row4 d c
Run Code Online (Sandbox Code Playgroud)
我的实际数据有很多行和列,每次循环时数据都会发生变化,所以我需要一种不引用特定列名和行名的方法.
期望的结果如下:
col1 col2
row1 b b
row2 a b
row3 d c
row4 c a
Run Code Online (Sandbox Code Playgroud) 下面的代码可以用SoStuck现有的对象加载:
Im <- c(1,2,3,4)
Stuck <- c(6,7,8,9)
SoStuck <- data.frame(Im, Stuck)
save.image("image.RData")
Run Code Online (Sandbox Code Playgroud)
然后我退出了这个会话并开始另一个。我这样做:
load("image.RData")
有用:
SoStuck
Im Stuck
1 1 6
2 2 7
3 3 8
4 4 9
Run Code Online (Sandbox Code Playgroud)
但是,如果我这样做:
myfunction <- function()
{
Im <- c(1,2,3,4)
Stuck <- c(6,7,8,9)
SoStuck <- data.frame(Im, Stuck)
save.image("image.RData")
}
myfunction()
Run Code Online (Sandbox Code Playgroud)
重新启动R,加载然后调用没有找到对象:
load("image.RData")
SoStuck
Error: object 'SoStuck' not found
Run Code Online (Sandbox Code Playgroud)
我也试过 return(save.image("image.RData"))那个循环中并得到相同的错误。
如果文件保存在函数中,有人知道我需要更改什么才能加载文件吗?谢谢。