Search code examples
rvariables

How to refer to a variable in the Shapiro test?


I would like to ask you about shapiro test in R. How can I refer to a variable in test result?

r<-shapiro.test(reszty)
r

    Shapiro-Wilk normality test

data:  reszty
W = 0.9226, p-value = 4.967e-07

I would like to refer to w and to p-value.


Solution

  • In general, for function calls in R you can extract information after assigning to a variable doing this:

    r<-shapiro.test(reszty)
    r$statistic (for W) or r$p.value (for p-val)
    

    or you can not assign to a variable, but extract straight away:

    shapiro.test(reszty)$p.value