Reputation: 1035
I have the data with columns
Time - AgentID -- SimulationID -- discountFactor -- displacement
For each by =.(AgentID,SimulationID,discountFactor)
, I want to calculate acf(displacement, doPlot=False)$acf
, and put its output to new data.table dStat
. However, since the size of the output of acf(...)$acf
is less than that of Time
, I can't directly define a new column, so I need to create a new data.table.
How can I do this?
A portion of my whole data set:
structure(list(Time = c(2.00099550677104, 2.00108827485947, 2.00108827485947,
2.00108827485947, 2.00108827485947, 2.00108827485947, 2.00108827485947,
2.00108827485947, 2.00108827485947, 2.00108827485947, 2.00108827485947
), AgentID = c(40L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L),
SimulationID = c(2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L), discountFactor = c(0.2, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8,
0.8, 0.8, 0.8, 0.8), displacement = c(-4L, -7L, -1L, 6L,
-6L, 6L, -1L, -4L, 0L, 0L, -3L)), row.names = c(NA, -11L), class = c("data.table",
"data.frame"), .internal.selfref = <pointer: 0x55a2cca3bde0>, sorted = "Time")
Upvotes: 0
Views: 91
Reputation: 2777
Like this?
dt[, .(acf = c(acf(displacement, plot = FALSE)$acf)), .(AgentID, SimulationID, discountFactor)]
Does't really do much with your sample data as rows are unique on the by
.
Upvotes: 1