之前有关于这个话题的问题,但我仍然在努力传播这个问题。我希望每个state
人都有自己的温度值列。
这是dput()
我的一个数据。我会打电话的df
structure(list(date = c("2018-01-21", "2018-01-21", "2018-01-20",
"2018-01-20", "2018-01-19", "2018-01-19", "2018-01-18", "2018-01-18",
"2018-01-17", "2018-01-17", "2018-01-16", "2018-01-16", "2018-01-15",
"2018-01-15", "2018-01-14", "2018-01-14", "2018-01-12", "2018-01-12",
"2018-01-11", "2018-01-11", "2018-01-10", "2018-01-10", "2018-01-09",
"2018-01-09", "2018-01-08", "2018-01-08", "2018-01-07", "2018-01-07",
"2018-01-06", "2018-01-06", "2018-01-05", "2018-01-05", "2018-01-04",
"2018-01-04", "2018-01-03", "2018-01-03", "2018-01-03", "2018-01-03",
"2018-01-02", "2018-01-02"), tmin = c(24, 31, 31, 29, 44, 17,
32, 7, 31, 7, 31, 6, 30, 13, 30, 1, 43, 20, 33, 52, 42, 29, 30,
29, 26, 32, 33, -2, 29, 0, 23, 3, 19, 11, NA, -3, 22, -3, 24,
-4), state = c("UT", "OH", "UT", "OH", "UT", "OH", "UT", "OH",
"UT", "OH", "UT", "OH", "UT", "OH", "UT", "OH", "UT", "OH", "UT",
"OH", "UT", "OH", "UT", "OH", "UT", "OH", "UT", "OH", "UT", "OH",
"UT", "OH", "UT", "OH", "UT", "OH", "UT", "OH", "UT", "OH")), class = "data.frame", row.names = c(NA,
-40L), .Names = c("date", "tmin", "state"))
我运行的代码是
df %>% spread(state,tmin)
我希望给我以下格式
date UT OH
... ... ...
但我收到错误消息
错误:行 (36, 38), (35, 37) 的标识符重复
我尝试了一些不同的东西。我尝试过的一件事是按日期分组。我在想同一日期的行会导致spread
. add_rownames()
我还尝试使用然后使用创建新行spread(state,tmin)
,但这也未能解决问题。