Greetings,

I am getting errors with the following code because the software does not recognize a change in shapiro.test(x)$data.name in line 3 of the function SWtest.

SWtest <- function(x) {

cat("S-W statistic for",

shapiro.test(x)$data.name,"is",

round(shapiro.test(x)$statistic,4),

"with p-value =",

round(shapiro.test(x)$p.value,4),"\n")

}

How am I to extract the data.name variable in this situation so the sentence output

reflects the correct variable? x should be changing.

Source:

seed <- 1234

x1 <-rnorm(10, mean = 5, sd = 3)

x2 <- runif(10, min = 2, max = 4)

shapiro.test(x1)

shapiro.test(x2)

SWtest <- function(x) {

cat("S-W statistic for",

shapiro.test(x)$data.name,"is",

round(shapiro.test(x)$statistic,4),

"with p-value =",

round(shapiro.test(x)$p.value,4),"\n")

}

SWtest(x1)

SWtest(x2)

Output:

SWtest(x1)

S-W statistic for x is 0.9475 with p-value = 0.6388

SWtest(x2)

S-W statistic for x is 0.9403 with p-value = 0.5562

Thank you.

Sincerely,

Mary A. Marion