Assuming you have a data frame in R with multiple columns and you have identified specific columns that you want to perform the Shapiro test on, you can use a loop to iterate through the columns in your vector and perform the Shapiro test on each column. Here's an example:
main.r269 chars15 lines
In this example, we have a data frame df with columns x, y, and z. We've created a vector cols containing the column names of x and z that we want to perform the Shapiro test on.
We then use a for loop to iterate through each column name in cols. Within the loop, we use the shapiro.test() function on the column by using df[[col]] to reference the column in the data frame.
Note that the shapiro.test() function tests the null hypothesis that the data is normally distributed. It returns a list containing the Shapiro-Wilk test statistic (W) and the p-value of the test (p). You may want to capture these values or perform additional actions based on the outcome of the test.
gistlibby LogSnag