creation of a dataframe in for cycle

The first block of code does nothing helpful here because it does not expose the data being used. a reprex. See the FAQ. So the problem can only be addressed generically.

As I understand the problem, it is to begin with a vector of values, x, and then derive through some function f a new vector, y, which will be recycled as x to f to derive a new vector y with the goal of making a data .frame object d with columns composed of x_1 \dots x_{10000}.

  1. Write f for the case of one vector
  2. Create a receiver object d of dimensions equal to the planned result, with the first column consisting of x_1 and the remaining columns set to NA.
  3. Find a function f' to apply f successively to populate d

Candidates for f' are the apply family, it's {purrr} implementations which may or may not seem more user-friendly, and for1. It might call f recursively. One possible form for f` is

sapply(2:1e4,f)
1 Like