1

下面是一个动物园对象的摘录,我试图winsorpsych包中使用它进行winsorize:

x <- structure(c(0.0400337546529555, -0.0320371743076633, 0.0106006766976862, 
-0.011406282992093, -0.018676165248018, 0.0275956214868875, 0.00473575019758404, 
0.0986083620222542, 0.00615420656427005, 0.00709069372334476), .Names = c("1984-01", 
"1984-02", "1984-03", "1984-04", "1984-05", "1984-06", "1984-07", 
"1984-08", "1984-09", "1984-10"), index = structure(c(5113, 5144, 
5173, 5204, 5234, 5265, 5295, 5326, 5357, 5387), class = "Date"), class = c("zooreg", 
"zoo"), frequency = 1)

我用:

winsor(x, trim=0.1)

我得到以下信息:

function () 
.Last.value
<environment: namespace:gdata>

我尝试了具有相同类(即zoozooreg)的以下数据的函数:

a <- structure(c(1, 2, 3), .Dim = c(3L, 1L), .Dimnames = list(NULL, 
        "a"), index = structure(c(5113, 5144, 5173), class = "Date"), frequency = 1, class = c("zooreg", 
    "zoo"))

它可以正常工作,a但不确定为什么它会针对特定类型的数据返回上述内容x

4

1 回答 1

0

xinwinsor必须是向量、矩阵或 data.frame。不支持zoo对象。首先转换/提取您的数据,例如:

winsor(coredata(x), trim=0.1)

> winsor(coredata(x), trim=0.1)
     1984-01      1984-02      1984-03      1984-04      1984-05      1984-06 
 0.040033755 -0.020012266  0.010600677 -0.011406283 -0.018676165  0.027595621 
     1984-07      1984-08      1984-09      1984-10 
 0.004735750  0.045891215  0.006154207  0.007090694

更新

OP 中的x问题缺少维度,添加 dim(x)=c(10,1) 使其工作:

> dim(x)=c(10,1)
> winsor(x)
                      X
1984-01-01  0.030083248
1984-02-01 -0.012860259
1984-03-01  0.010600677
1984-04-01 -0.011406283
1984-05-01 -0.012860259
1984-06-01  0.027595621
1984-07-01  0.004735750
1984-08-01  0.030083248
1984-09-01  0.006154207
1984-10-01  0.007090694
于 2016-03-17T13:07:05.383 回答