我是 R 中 data.table 的菜鸟,我想在此示例中跳过 z=3 的最后一个值:
> DT = data.table(y=c(1,1,2,2,2,3,3,3,4,4),x=1:10,z=c(1,1,1,1,2,2,2,2,3,3))
> DT[,list(list(predict(smooth.spline(x,y),c(4,5,6))$y)),by=z]
Error in smooth.spline(x, y) : need at least four unique 'x' values
如果我只是删除 z=3 我会得到我想要的答案:
> DT = data.table(y=c(1,1,2,2,2,3,3,3),x=1:8,z=c(1,1,1,1,2,2,2,2))
> DT[,list(list(predict(smooth.spline(x,y),c(4,5,6))$y)),by=z]
z V1
1: 1 2.09999998977689,2.49999997903384,2.89999996829078
2: 2 0.999895853971133,2.04533519691888,2.90932467439562
多么棒的包裹啊!