Re: [R] store list objects in data.table

2024-09-21 Thread Bert Gunter
Well, you may have good reasons to do things this way -- and you certainly do not have to explain them here. But you might wish to consider using R's poly() function and a basic nested list structure to do something quite similar that seems much simpler to me, anyway: x <- rnorm(20) df <- data.fr

Re: [R] store list objects in data.table

2024-09-21 Thread CALUM POLWART
I think there is a typo in your reprex l(x^2) ?? mydt[1,2] contains a list. Which when unlisted contains a load of data. I'm not sure what you are asking for? Are you trying to unlist that and have it as a row? Sort of pivot.wider if you like or unnest in tidyverse concepts? I think the data.tab

Re: [R] store list objects in data.table

2024-09-21 Thread Rui Barradas
Às 22:25 de 21/09/2024, Naresh Gurbuxani escreveu: I am trying to store regression objects in a data.table df <- data.frame(x = rnorm(20)) df[, "y"] <- with(df, x + 0.1 * x^2 + 0.2 * rnorm(20)) mydt <- data.table(mypower = c(1, 2), myreg = list(lm(y ~ x, data = df), lm(y ~ x + I(x^2), data = df

[R] store list objects in data.table

2024-09-21 Thread Naresh Gurbuxani
I am trying to store regression objects in a data.table df <- data.frame(x = rnorm(20)) df[, "y"] <- with(df, x + 0.1 * x^2 + 0.2 * rnorm(20)) mydt <- data.table(mypower = c(1, 2), myreg = list(lm(y ~ x, data = df), lm(y ~ x + I(x^2), data = df))) mydt #   mypower    myreg #    #1:   1