Skip to content

Instantly share code, notes, and snippets.

@chelseaparlett
Last active March 24, 2022 17:07
Show Gist options
  • Save chelseaparlett/6650469fd800367eddbb37033e78a122 to your computer and use it in GitHub Desktop.
Save chelseaparlett/6650469fd800367eddbb37033e78a122 to your computer and use it in GitHub Desktop.
library(tidyverse)
# create named list
l <- list(x = data.frame(a = rnorm(10), b = rnorm(10)),
y = data.frame(a = rnorm(10), b = rnorm(10)),
z = data.frame(a = rnorm(10), b = rnorm(10)))
for (i in names(l)){
if (i %in% c("x", "y")){ # if the name of the list item is in a specified sublist
l[[i]] <- l[[i]] %>% mutate(c = a + 1) # then do the mutate
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment