0

这是我的代码的一部分。

library(reshape2)
setwd("C:/Users/Desktop/WildFires/FedFire8004/FedFire8004")
load("fedfire8004.rda")
library(reshape2)
Acres <- melt(fedfire8004$acres)

它读取具有纬度、经度、时间(每月)和值的数据,并将数据转换为以下格式(英亩)。问题是在输出中,第 1 个月和第 10 个月之间没有区别。它们都存储在例如 1983.10 的第 1 个月和 1980 年的第 10 个月。我是否可以将它们存储为不同的格式,例如第 1 个月的 1980.1 和 1980.10和 10。

     lat  lon  month      Acre
1  -118.5 48.5 1983.10    1692.9
2  -117.5 48.5 1983.10      11.1
3  -116.5 48.5 1983.10       0.0
4  -115.5 48.5 1983.10       1.1
5  -114.5 48.5 1983.10       0.0
6  -113.5 48.5 1983.10     151.2
7  -112.5 48.5 1983.10       5.0
4

1 回答 1

2

我认为问题出在melt应用type.convert到数据的暗淡名称上。为避免字符到数字的转换,您可以将 替换.-. 尝试:

dimnames(fedfire8004$acres)$month <- sub("\\.", "-",
                                         dimnames(fedfire8004$acres)$month)

然后melt再次申请,您应该会看到1980-11980-10

于 2013-10-20T16:38:36.100 回答