我想从这个结构中走出来:
game_id team pts
1 400597848 TOWS 53
2 400597848 COFC 50
3 400595519 ILL 49
4 400595519 WIS 68
对此:
game_id team1 pts1 team2 pts2
1 400597848 TOWS 53 COFC 50
3 400595519 ILL 49 WIS 68
这是示例数据:
d <- structure(list(game_id = c(400597848L, 400597848L, 400595519L,
400595519L), team = c("TOWS", "COFC", "ILL", "WIS"), pts = c(53L,
50L, 49L, 68L)), .Names = c("game_id", "team", "pts"), row.names = c(NA,
4L), class = "data.frame")
我已经尝试使用tidyr
并遵循本教程:
http: //www.cookbook-r.com/Manipulating_data/Converting_data_between_wide_and_long_format/
但是,当我尝试:
spread(d, team, pts)
我得到所有团队的重复列,但不想要所有组合。