The result of a function, for example a t-test, can be assigned to an R object. The str()
function can be used to list the elements of the object.
ttest <- t.test( BMI ~ Walkability, data=BEPAS)
str(ttest )
We’ve seen before that the dollar sign ($
) can be used to subset a data frame (to select a column of a data frame). The same sign can be used to subset our R object ttest
.
In the code below the test method is assigned to the R object m
, and the p-value is assigned to R object p
.
m <- ttest$method
p <- round (ttest$p.value,3) #the round() function is used to round the p-value to 3 decimals