Hi there! So this is a simplification of my problem.
I have a dataframe like this:
df <- data.frame(name=c("lucas","julio","jack","juan"),number=c(1,15,100,22))
And i have a function that creates new values for every name, like this:
var_number <- function(x) {
example<- df %>% filter(name %in% unique(df$name)[x]) %>%
select(-name) %>% mutate(
value1=number/2^5,
value2=number^5)
(example)}
var_number(1)
0.03125 1
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:
result<- bind_rows(var_number(1),var_number(2),var_number(3),var_number(4))
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.
Thank you!