Open ggrothendieck opened 2 years ago
FYI @ggrothendieck: https://sebkrantz.github.io/collapse/reference/indexing.html. Works inside all data masking environments and can be efficiently transformed to regular pdata.frame for estimation using the to_plm()
function.
Some background/explanation why things like with
do not work as expected with a pdata.frame
: This is due to a pdata.frame not holding pseries in columns but the plain base class. A pseries is created only when columns are extracted (cf. the first vignettte "While extracting a series from a pdata.frame, a pseries is created, which is the original series with the index attribute.").
Yes, it is somewhat unintuitive.
Here is an example:
library(plm)
df <- data.frame(id = c(1,1,2), time = c(1,2,1), f = factor(c("a", "a", "b")), n = c(1:3))
pdf <- pdata.frame(df)
class(pdf$f)
#> [1] "pseries" "factor"
lapply(pdf, class)
#> $id
#> [1] "factor"
#>
#> $time
#> [1] "factor"
#>
#> $f
#> [1] "factor"
#>
#> $n
#> [1] "integer"
Suggest adding
transform
,with
andcbind
methods. Currently none of these work:This one does work but it is not the best style with R and does not fit in with pipes. E2 had to be written 3 times to avoid overwriting E.