stackoverflow!
How can I both split and duplicate dataframe using dplyr
? Just imagine, that I have got
a data frame with grouping variable (i.e. group
), sample id (i.e. sample
) and value.
library(tidyverse)
df <- tibble(group = c(rep(LETTERS[1:3], 3), "mix", "mix"),
sample = paste0("sample", seq(1, 11)),
value = rnorm(11, 20, sd = 30))
I need to split this dataframe into two more dataframes by mix group and sample from this group. First group will be all dataframe without sample11
row, second — without sample10
row. Something like this but more modern way. I believe there's a function for this)
list(
df1 = df %>% filter(sample != "sample10"),
df2 = df %>% filter(sample != "sample11")
)
I need to do it for a tens of target samples and then map a function for every df.