1

I have a vector of inputs in R and a function f.

inputs <- c('input1','input2','input3',...,'input10')

I want to obtain output <- c(f(input1),f(input2),...,f(input10)) without writing this out.

How can I do this in an efficient manner, and without using a for loop? Also, I'd like to do this without referring to the subscript on input (I just numbered it for the sake of this question).

Further, f('input1') does not work while f(input1) does. How can I resolve this?

1 Answers1

1

Hope Vectorize could help

Vectorize(f)(inputs)
ThomasIsCoding
  • 96,636
  • 9
  • 24
  • 81