Question: I have three data frames similar to:

```
    Value Time Colour  Fruit 
1    9.0    1  Orange  Apple 
2    9.5    2  Orange  Apple 
3   10.0    1  Red     Apple 
4    9.0    2  Blue    Apple 
5    9.5    1  Blue    Apple 
6   10.0    2  Blue    Pear
7    1.0    1  Blue    Pear 
8    2.0    2  Red     Pear 
9    3.0    1  Red     Pear 
10   2.0    2  Orange  Pear 
11   1.0    1  Blue    Mango 
12   3.0    2  Blue    Mango
13   2.0    2  Red     Mango
14   3.0    1  Red     Mango
15   2.0    2  Orange  Mango
16   1.0    1  Blue    Banana 
17   3.0    2  Blue    Banana
18   2.0    2  Red     Banana
19   3.0    1  Red     Banana
20   2.0    2  Orange  Banana 

```

...listed in my\_list:

```
my_list<- list(df1=df1, df2=df2, df3=df3)

```

for plotting the data later (grouped barplot using facet\_grid) I would like to relevel the values of Fruit and Colour like I could do for single data frames using fct\_relevel:

```
Data <- Data %>% 
  mutate(Colour = fct_relevel(Colour,"Blue", "Red", "Orange")) %>% 
  mutate(Fruit  = fct_relevel(Fruit, "Apple", "Mango", "Banana", "Pear"))

```

Thanks for any help!

Answer: 
Since you're using dplyr, one approach is with `map` from `purrr`:

```
library(dplyr)
library(purrr)
mylist <- my_list %>% 
  map(~ .x %>%
        mutate(Colour = fct_relevel(Colour,"Blue", "Red", "Orange")) %>%
        mutate(Fruit = fct_relevel(Fruit, "Apple", "Mango", "Banana", "Pear")))

```
You can use lapply to loop over the list of df's assuming that the levels of the df's are all the same.

```
my_list <- lapply(my_list, function(x){ x %>% 
                                         mutate(Colour = fct_relevel(Colour,"Blue", "Red", "Orange"), 
                                                Fruit = fct_relevel(Fruit, "Apple", "Mango", "Banana", "Pear"))
})

```