rnorouzian
rnorouzian

Reputation: 7517

Having a function only output the numberic answer

I was wondering if there is a way I can have Gi1 an subsequently UrUr in the R code below only provide the NUMBERIC ANSWER and NOT the extra word B10 that currently comes with the numberic answer?

Note: I'm aware of using [[ith output]] but I will need that function itself to provide purely number from the begining so I don't need to use many [[]] later in my code.

 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

Upvotes: 1

Views: 42

Answers (1)

LyzandeR
LyzandeR

Reputation: 37889

Just use unname within the Gi1:

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)) }

And then it will be fine.

> UrUr <- sapply(c(1/2, 1, sqrt(2)/2 ), Gi1)
> UrUr
[1] 0.3015327 0.1579931 0.2197861

Upvotes: 2

Related Questions