Problem trying to rename variables generated as shapiro_test output

I am trying to rename the output variables from a Shapiro Wilks Test into a dataframe and then rename the output statistic and p value so I can merge it with other data.

dfSW_test_all <- df_data %>% shapiro_test(diff)
dfSW_test_all <- rename(SW_test_all, statistic = SW_diff_all, p = p_diff_all)

The following code runs

dfSW_test_all <- df_data %>% shapiro_test(diff)

Here is the str(dfSW_test_all)

tibble [1 × 3] (S3: tbl_df/tbl/data.frame)
** variable : chr "diff"** ** statistic: Named num 0.782**
** ..- attr(*, "names")= chr "W"**
** $ p : num 7.24e-11**

But this code

dfSW_test_all <- rename(SW_test_all, statistic = SW_diff_all, p = p_diff_all)

produces the following error:

Error in rename():
! Can't rename columns that don't exist.
:heavy_multiplication_x: Column SW_diff_all doesn't exist.
Run rlang::last_trace() to see where the error occurred.

I think you have to switch the order of your names. The help file says " rename() changes the names of individual variables using new_name = old_name syntax"

Huh ...who'd thunk that one. You did so Thanks! I tried that and it works. I would think that the syntax would be that the variable being renamed would be first but then again I guess I can sort of see the reverse logic as well.
Anyway thanks for your help

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.