rpairwise.wilcox.test# Using Mann Whitney to create list of pvalues

I am looking to find a way to write a for loop using a Mann Whitney Wilcox test in R. The command I have seen online is wilcox.test(). But I am trying to do so for large data sets that have thousands of columns. I have not found any luck online for other resources.

I have this data frame, DF1, and two groups (Sam and Anna) under DF1$Name. The nonparametric approach with two groups is desired for this data, and I want to run a for loop to get the p-value for each of the column names (Companies, Store, Cars, and Homes) when comparing the two groups (Sam and Anna). Is there an efficient way to do so?

DF1:

Name | Companies | Store | Cars | Homes |
---|---|---|---|---|

Sam | 23 | 10 | 10 | 8 |

Anna | 21 | 8 | 7 | 4 |

Anna | 22 | 5 | 5 | 5 |

Sam | 24 | 5 | 6 | 8 |

Anna | 45 | 6 | 7 | 4 |

My goal is to get a list of p-values generated. Any suggestions would be appreciated! Thank you!

```
# DF1
Name <- c("Sam", "Anna", "Anna", "Sam", "Anna")
Companies <- c(23, 21, 22, 24, 45)
Store <- c(10, 8, 5, 5, 6)
Cars <- c(10, 7, 5, 6, 7)
Home <- c(8, 4, 5, 8, 4)
DF1 <- data.frame(Name, Companies, Store, Cars, Home)
```

I have tried this so far, and it definitely doesnt work, but I feel this is something towards I want to get. The code below was the first part of the test that was derived from here. But now is there a way to grab all of the p-values here in a list next to the descriptors (companies, store, cars, homes?)

```
DF1$Group <- as.factor(DF1$Name)
Z <- lapply(DF1[-1], function(x){
wilcox.test(x ~ DF1$Name)
})
```

Solution

Here is one way:

```
library(tidyverse)
DF1 %>%
select_if(is.numeric) %>%
map_df(~ broom::tidy(wilcox.test(. ~ Name)), .id = 'var')
```

```
# A tibble: 4 × 5
var statistic p.value method alternative
<chr> <dbl> <dbl> <chr> <chr>
1 Companies 2 0.8 Wilcoxon rank sum exact test two.sided
2 Store 2.5 1 Wilcoxon rank sum test with continuity correction two.sided
3 Cars 2 0.767 Wilcoxon rank sum test with continuity correction two.sided
4 Home 0 0.128 Wilcoxon rank sum test with continuity correction two.sided
```

- Installing R on Linux: configure: error: libcurl >= 7.28.0 library and headers are required with support for https
- How to do ensembles with time series using AICc?
- planes3d expands and draws the area based on the sphere's radius
- How to extract tag code itself using R, rvest
- How to Display or Print Contents of Environment in R
- How to use Windows user credentials for proxy authentication in R/RStudio
- R reticulate specifying python executable to use
- Replace multiple Instances of a variable name in an R function and save the modified function
- Standardizing address formatting in R
- How to fix "failed to load cairo DLL" in R?
- Using grepl to filter columns names in specific range of columns
- changing the legends in ggplot2 to have groups of similar labels
- How to keep only unique rows but ignore a column?
- convert string date to R Date FAST for all dates
- Add subgroup text to plotly pie chart
- R Shiny : adjust height of DT datatable when fillContainer=TRUE,
- Why do R external pointers' "unusual copying semantics" mean they should not be used stand-alone?
- How to extract somo character after a string with a number of word which can change in R
- What does `se` stand for in geom_smooth(..., se = FALSE)?
- How to find number of rows greater than any values in R
- Align text and reduce space between text and parentheses in plotly hover info box
- Remove outer box of geom_bar plot with broken y-axis
- How to use lag/lead in mutate with an initial value?
- Is it possible to have a Shiny ConditionalPanel whose condition is a global variable?
- counting elements in one list in another list
- How to vectorize nested loops in R?
- Replace NA values with an incrementing sequence starting from the previous non-NA value
- How can I calculate the number of uniques in a row within a species matrix?
- How to perform operations on pairs of rows, based on a "distinguishing" column's values
- Mutate variable based on previous observations