在面板数据框中,我需要保持1 s的常量列。但是,在从data.frame转换为pdata.frame后,1s列会自动删除。有什么方法可以保留专栏吗?
答案 0 :(得分:1)
除了被删除之外,还有一条消息表明它是一个常数。
> xy <- data.frame(a = runif(5), b = runif(5), c = 1)
> pdata.frame(xy, drop.index = FALSE)
series c is constant and has been removed
a b
0.0236744922585785-0.950130922021344 0.0236744922585785 0.950130922021344
0.0879391168709844-0.295759258326143 0.0879391168709844 0.295759258326143
0.501141534885392-0.737975958967581 0.501141534885392 0.737975958967581
0.715363236144185-0.425528935389593 0.715363236144185 0.425528935389593
0.982470828806981-0.0960431189741939 0.982470828806981 0.0960431189741939
此行为已硬编码到pdata.frame
函数中。
if (length(cst.serie) > 0) {
if (length(cst.serie) == 1) {
cat(paste("series ", cst.serie, " is constant and has been removed\n",
sep = ""))
}
else {
cat(paste("series ", paste(cst.serie, collapse = ", x"),
" are constants and have been removed\n", sep = ""))
}
}
您可以通过电子邮件发送软件包维护者或自行删除该位(通过创建第二个函数)。假设有保持/不保持常数的理论依据。