Resolved: How would I compare the values in each set of 4 rows to one value (Wilcox test specifying mu)?

In this post, we will see how to resolve How would I compare the values in each set of 4 rows to one value (Wilcox test specifying mu)?

Question:

I need to compare the value in every four rows to one value (as mu) using a Wilcoxon signed rank sum test. For example if my data looks like this:
I am using a wilcox.test to compare each of the four values from df1 with one value as mu from df_stack2. Considering a df with just the first four rows it would be
I realise I could group every four rows through using:
I was hoping to adopt this for use in a mapply (so I could parallelise with future.apply due to the actual size of my dataframe), however, I am a little unsure as to how I could specify every four rows being compared to one value (in a separate dataframe) as mu?

Best Answer:

You can create your group using rep() and apply your function by group:
Output:
Similarly, using dplyr:
Output:
There is another approach that you might find interesting:
Output:

If you have better answer, please add a comment about this, thank you!

Source: Stackoverflow.com