Displaying 2 results from an estimated 2 matches for "carsdt".
Did you mean:
card
2024 Sep 22
2
store list objects in data.table
...their responses.
My data is organized in a data.table.? My goal is to perform analyses
according to some groups.? The results of analysis are objects.? If
these objects could be stored as elements of a data.table, this would
help downstream summarizing of results.
Let me try another example.
carsdt <- setDT(copy(mtcars))
carsdt[, unique(cyl) |> length()]
#[1] 3
carsreg <- carsdt[, .(fit = lm(mpg ~ disp + hp + wt)), by = .(cyl)]
#I would like a data.table with three rows, one each for "lm" object
corresponding to cyl value
carsreg[, .N]
#[1] 36
#Here each component of...
2024 Sep 22
1
store list objects in data.table
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.frame(x = x, y = x + .1*x^2 + rnorm(20, sd = .2))
result <-
with(df,