Now i have two new values for every name and i would like to create a loop to save each result in a new dataframe.
I know how to solve this particular problem, but i need a general solution that allows me to save the results of a function into a dataframe.
I;m looking for an automatic way to do something like this:
Since I would have to apply var_number around 1000 times and the lenght would change with every test i do.
There is anyway i can do something like this? I was thinking about doing it with "for", but i am not really sure about how to do it, I have just started with R and I am a total newbie.
Hi, Sidd.
Thank you for your answer.
I know how to solve this particular problem, I made it easy to focus in the second part:
I need to create a data frame of n rows where row 1 is function(1), row 2 is function(2) and so on. The size of n is going to chage everytime and i am not sure about how to do so. I was thinking about doing it with a loop, but i am not really sure about how to.
Another way might be something like this:
library(tidyverse) # contains purrr library
#an arbitrary function that always outputs a dataframe
# with a consistent number of columns, in this case 3
myfunc <- function(x){
data.frame(a=x*2,
b=x^2,
c=log2(x))
}
# iterate over 1:10 as inputs to myfunc, and
# combine the results rowwise into a df
purrr::map_dfr(1:10,
~myfunc(.))