I have the following function (of course is a little more complex than this!):
my_function <- function(id_table) {
data("mtcars")
if (id_table == "1_1") {
df <- mtcars %>%
filter(mpg > 19)
df
} else if (id_table == "1_2") {
df <- mtcars %>%
filter(disp < 100)
df
} else {
df <- mtcars %>%
select(vs, am, gear)
df
}
}
It works individually, as in:
foo <- my_function("1_1")
I want to give the function multiple inputs in a vector and another one to assign the objects resulting:
input_vector <- c("1_1", "1_2", "1_3")
names_vector <- sapply(input_vector, str_c, "t", sep = "")
I want to do what I did individually but instead giving my_function the input_vector and assign each one with the names provided by the names_vector. For instance, automatize this:
1_1t <- my_function("1_1")
1_2t <- my_function("1_2")
1_3t <- my_function("1_3")
PS: I want to put the "t" before the corresponding value of the vector but I do not know how.