Hi,
I would like to have all the results in dataframe or table:
List = list()
for(i in 1:100)
{
LM = lm(rnorm(10)~rnorm(10))
List[[length(List)+1]] = LM
}
I would like to have all iterations results, eg. first column will be number of iteration, next column will be formula, next column will be coefficients, etc.
General advice. Before attempting to iterate, I recommend you fully produce one of the results manually yourself.
That means if you want certain things in a dataframe, that you construct such a dataframe.
Afterwords generalising and producing similar in a loop becomes a strait forward exercise. And often you can use purrr map rather than for loop
I do baby steps because I do not know the other way.
Can you show me what you would do in order to fully produce one of the results manually, please ? That you suggested in your reply.
I have read about broom and it's functions. For example this works:
I think you're going about this the wrong way. In my opinion, you should use all 3 of broom's tidying functions to generate the summary statistics that you need. Read more about them here.
Thank you very much, that is the way it should be,
anyway I still try to somehow to change table below so names/values in rows in column "My_elements" will go to columns and V1:V5 will go to row names. I tried pivot longer and pivot_wider but no success. If anybody has got an idea how to do it, I would be very grateful.
Hi again, I know that this post has got a solution but for learning/execising purposes only I tried to reshape this above dataframe and come up with this:
So this is almost what I wanted (that My_elements variable would go to columns) but my question is how to place everything within 1-5 rows only in order to have a dataframe without NULL values in many places ? Is it doable ?