为什么要舍入我的浮点数?

Why dcast round my float numbers?

我有一个数据框:

> head(df)
     nome   Class_Name area_class       date
1 Arataca agropecuaria    25.7751 1973-07-26
2 Arataca         agua     0.2918 1973-07-26
3 Arataca       bosque     0.0207 1973-07-26
4 Arataca       bosque     3.9335 1973-07-26
5 Arataca         mata    69.9513 1973-07-26
6 Arataca solo exposto     0.0276 1973-07-26

当我用 dcast 函数转换它时,值列不保持为浮点数:

dcast(df, nome+date~Class_Name, value.var = "area_class")
            nome       date agropecuaria agua bosque mata solo exposto
1              Arataca 1973-07-26            1    1      2    1            1
2            Buerarema 1973-07-26            1    0      2    1            1
3              Camacan 1973-07-26            1    0      1    1            0
4               Camamu 1973-07-26            1    1      2    1            1
5            Igrapiúna 1973-07-26            1    1      2    1            1
6               Ilhéus 1973-07-26            1    1      2    1            1
7              Itabuna 1973-07-26            1    0      2    1            1
8              Itacaré 1973-07-26            1    1      2    1            1
9              Ituberá 1973-07-26            1    1      2    1            1
10               Maraú 1973-07-26            1    1      2    1            1
11        Nilo Peçanha 1973-07-26            1    0      2    1            0
12 São José da Vitória 1973-07-26            1    1      2    1            0
13                 Una 1973-07-26            1    1      2    1            1
14             Uruçuca 1973-07-26            1    1      2    1            1

为什么 "area_class" 是一个数字 class 我转换它时不保留为浮点数?

OP 的 post 中的输出可能是因为重复的行使得 dcast fun.aggregate 执行 length 作为默认选项。为了防止这种情况,创建一个序列列或聚合 value.var(取决于要求)

dcast(df, nome+date~Class_Name, value.var = "area_class", fun.aggregate = mean)