有一个函数只输出数字答案
Having a function only output the numberic answer
我想知道是否有一种方法可以让 Gi1
随后 UrUr
在下面的 R 代码中 只提供数字答案而不是额外的词 B10
当前带有数字答案?
注意: 我知道使用 [[ith output]]
但我需要该函数本身从一开始就提供纯数字,所以我不需要使用许多 [[]]
稍后在我的代码中。
library(BayesFactor)
ttype = 1
t = -.742
N1 = 102
N2 = ifelse(ttype==1, NA, 102)
rscale = sqrt(2)/2
tl = 1
dexp = -1
Gi1 <- function(x) {
ttest.tstat(t, N1, ifelse(ttype==1, F, N2),
nullInterval = c(ifelse(dexp==-1, -Inf, Inf),
ifelse(tl==1, 0, Inf)),rscale = x, simple = TRUE) }
UrUr <- sapply(c(1/2, 1, sqrt(2)/2 ), Gi1)
UrUr
只需在 Gi1
:
中使用 unname
Gi1 <- function(x) {
unname(ttest.tstat(t, N1, ifelse(ttype==1, F, N2),
nullInterval = c(ifelse(dexp==-1, -Inf, Inf),
ifelse(tl==1, 0, Inf)),rscale = x, simple = TRUE)) }
然后就好了
> UrUr <- sapply(c(1/2, 1, sqrt(2)/2 ), Gi1)
> UrUr
[1] 0.3015327 0.1579931 0.2197861
我想知道是否有一种方法可以让 Gi1
随后 UrUr
在下面的 R 代码中 只提供数字答案而不是额外的词 B10
当前带有数字答案?
注意: 我知道使用 [[ith output]]
但我需要该函数本身从一开始就提供纯数字,所以我不需要使用许多 [[]]
稍后在我的代码中。
library(BayesFactor)
ttype = 1
t = -.742
N1 = 102
N2 = ifelse(ttype==1, NA, 102)
rscale = sqrt(2)/2
tl = 1
dexp = -1
Gi1 <- function(x) {
ttest.tstat(t, N1, ifelse(ttype==1, F, N2),
nullInterval = c(ifelse(dexp==-1, -Inf, Inf),
ifelse(tl==1, 0, Inf)),rscale = x, simple = TRUE) }
UrUr <- sapply(c(1/2, 1, sqrt(2)/2 ), Gi1)
UrUr
只需在 Gi1
:
unname
Gi1 <- function(x) {
unname(ttest.tstat(t, N1, ifelse(ttype==1, F, N2),
nullInterval = c(ifelse(dexp==-1, -Inf, Inf),
ifelse(tl==1, 0, Inf)),rscale = x, simple = TRUE)) }
然后就好了
> UrUr <- sapply(c(1/2, 1, sqrt(2)/2 ), Gi1)
> UrUr
[1] 0.3015327 0.1579931 0.2197861