我已经尝试过关于stackoverflow的多个帖子的解决方案,但是都没有成功。如果您认为这是重复项,则不是。我已经提到过this和this的帖子。
[
{left: 15, top: 15, group: "groupThree"},
{left: 25, top: 30, group: "groupThree"},
{left: 18, top: 10, group: "groupTwo"},
{left: 18, top: 25, group: "groupFour"},
{left: 20, top: 50, group: "groupOne"},
{left: 25, top: 15, group: "groupSix"},
{left: 30, top: 30, group: "groupSix"}
{left: 28, top: 25, group: "groupFive"},
];
我需要将observation_date列中的值转换为多列,并将total_duration的值添加到同一列中。我尝试过的所有解决方案最终都会得到0或1。
从Post 1尝试的解决方案
> head(t)
locality_id observer_id observation_date total_duration total_dist total_area
1 L1366429 obsr529319 2017-01-12 100 1.609 0
2 L1366429 obs613305 2017-10-09 120 2.000 0
3 L1366429 obsr644174 2017-11-01 90 1.000 0
4 L1619491 obs729967 2017-03-27 240 2.000 0
5 L1845345 obs360918 2017-09-30 120 5.000 0
6 L1845345 obs575633 2017-10-27 45 0.300 0
localities species observation loc_type prot_type num_observers
1 Eravikulam National Park Ficedula nigrorufa 1 H Traveling 7
2 Eravikulam National Park Ficedula nigrorufa 0 H Traveling 1
3 Eravikulam National Park Ficedula nigrorufa 1 H Traveling 2
4 Munnar Ficedula nigrorufa 0 H Traveling 8
5 Nelliampathy Hills--General Area Ficedula nigrorufa 0 H Traveling 1
6 Nelliampathy Hills--General Area Ficedula nigrorufa 0 H Traveling 3
Abundance
1 1
2 0
3 1
4 0
5 0
6 0
我最终得到一个0和1的数据帧。
从Post 2开始尝试的解决方案
library(data.table)
tcast <- dcast(t, locality_id + localities + species +observer_id
~ observation_date, value.var="total_duration")
Aggregate function missing, defaulting to 'length'
除了上述错误外,第二种解决方案是给我一个怪异的表。
请帮助!最近几天一直在为此苦苦挣扎!