Given a list, l, of data frame objects:
l = list()
l$`__a` <- data.frame(`__ID` = stringi::stri_rand_strings(10, 1), col = stringi::stri_rand_strings(10, 1), check.names = F )
l$`__b` <- data.frame(`__ID` = stringi::stri_rand_strings(10, 1), col = stringi::stri_rand_strings(10, 1), check.names = F )
l$`_c` <- data.frame(`__ID` = stringi::stri_rand_strings(10, 1), col = stringi::stri_rand_strings(10, 1), check.names = F )
How can I automate the following such that it works for any input list l of a similar structure?
l2 = list()
l2$`__a`$`__ID.new` <- paste0("ABC_",l$`__a`$`__ID`)
l2$`__a`$`col.new` <- paste0("DEF_",l$`__a`$`col`)
l2$`__b`$`__ID.new` <- paste0("ABC_",l$`__b`$`__ID`)
l2$`__b`$`col.new` <- paste0("DEF_",l$`__b`$`col`)
I'm looking for a solution that:
- includes all list items starting with
__inl2 - allows for manipulating each data frame column in a different way and adding a
.newsuffix to the column name - adds all extra columns where no manipulation is required "as is"
I've attempted using lapply and writing loops that use eval(parse( ).