0

I have several dataframe, named "df.1","df.2",.....until "df.100".

I want to create a new dataframe for each of them, such as:

df.1.new <- df.1  %>% filter (var.1>=100)  %>% group_by (var.2)  %>% slice (which.min(var.3))

How can I apply the code to all thses dataframe from "df.1" to "df.100"?

1 Answer 1

2

Get the dataframes in a list and apply the code to each list element.

library(dplyr)

purrr::map(mget(paste0('df.', 1:100)), function(data) {
  data  %>% filter(var.1>=100)  %>% group_by(var.2)  %>% slice(which.min(var.3))
}) -> result
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.