I am trying to make my code shorter using loops. I have an object, of which several "sub-objects" exist, which I appended with a letter, i.e.
my_object_a
my_object_b
my_object_c
Now I was planning on manipulating those objects, say I want to log2 the second column of each of those.
I thought it would be handy to just store a, b, and c in a vector and then using paste()
and get()
like so:
letter <- c("a", "b", "c")
for (i in 1:length(letter){
get(paste0("my_object_", id[i])) <- MadeUpFunction(get(paste0("my_object_", id[i])))
}
My question is: how would one usually approach such kind of problem in order to avoid automate a repetitive task?
I feel like somebody might suggest a named list here, but then I have to pop them back out of the list, right?
Btw, the function in the loop as well as the exact object dont really matter, lets just say its each a complex object and I would apply a custom function to them, for example normalization from a package.
Any help will be appreciated.