我有一個(gè)長(zhǎng)格式的數(shù)據(jù)框,其中包含相同日期和人的多個(gè)條目。jj <- data.frame(month=rep(1:3,4), student=rep(c("Amy", "Bob"), each=6), A=c(9, 7, 6, 8, 6, 9, 3, 2, 1, 5, 6, 5), B=c(6, 7, 8, 5, 6, 7, 5, 4, 6, 3, 1, 5))我想將其轉(zhuǎn)換為寬格式并使其如下所示:month Amy.A Bob.A Amy.B Bob.B1 2 3123123123我的問題與此非常相似。我已經(jīng)在答案中使用了給定的代碼:kk <- jj %>% gather(variable, value, -(month:student)) %>% unite(temp, student, variable) %>% spread(temp, value)但它給出以下錯(cuò)誤:錯(cuò)誤:行(1、4),(2、5),(3、6),(13、16),(14、17),(15、18),(7、10),(8)的標(biāo)識(shí)符重復(fù),11),(9,12),(19,22),(20,23),(21,24)提前致謝。注意:我不想刪除多個(gè)條目。
- 3 回答
- 0 關(guān)注
- 612 瀏覽
添加回答
舉報(bào)
0/150
提交
取消