【发布时间】:2014-01-01 21:51:00
【问题描述】:
我想得到一个棘手的打印输出格式。这是我目前的数据框,它是由 for 循环和 rbind 构建的。
bets<- data.frame(status=character(), f_name=character(), d_name=character(), type_bet=character(), sec=character(),
spread=character(), total=character(), deriv=character(), book=character(), edge=character(),
my_f_price=character(), book_f_price=character(), my_d_price=character(), book_d_price=character())
示例打印输出:
status f_name d_name type_bet sec spread total deriv book edge my_f_price book_f_price my_d_price book_d_price
9:00 PM ET San Diego State Colorado State total h1 3.5 138.5 65 pin 12 120 -108 -120 -108
9:00 PM ET San Diego State Colorado State total h1 3.5 138.5 65 5d 10 120 -110 -120 -110
6:00 PM ET Cincinnati SMU total h1 8 125.5 59 pin 9 122 -103 -122 -113
8:00 PM ET Temple Rutgers total h1 1.5 150 70.5 pin 8 116 -108 -116 -108
8:00 PM ET Temple Rutgers total h1 1.5 150 70.5 5d 6 116 -110 -116 -110
8:05 PM ET Drake Evansville ml h1 7 136 0 5d 4 -214 -210 214 175
8:00 PM ET Northern Iowa Bradley total h1 12 133 62 5d 3 113 -110 -113 -110
6:00 PM ET Cincinnati SMU ml h1 8 125.5 0 5d 2 -242 -240 242 200
6:00 PM ET Cincinnati SMU total h1 8 125.5 58.5 5d 2 112 -110 -112 -110
有点难看,但是边缘列是它的排序方式,12、10、9、8、6、4、3、2、2。我想要做的是将一些条目组合在一起。当 f_name、d_name、type_bet 和 sec 都相同,并且唯一不同的列是 book 时,应将其视为一组。所以理想情况下,我希望打印输出如下所示:
status f_name d_name type_bet sec spread total deriv book edge my_f_price book_f_price my_d_price book_d_price
9:00 PM ET San Diego State Colorado State total h1 3.5 138.5 65 pin 12 120 -108 -120 -108
9:00 PM ET San Diego State Colorado State total h1 3.5 138.5 65 5d 10 120 -110 -120 -110
6:00 PM ET Cincinnati SMU total h1 8 125.5 59 pin 9 122 -103 -122 -113
6:00 PM ET Cincinnati SMU total h1 8 125.5 58.5 5d 2 112 -110 -112 -110
8:00 PM ET Temple Rutgers total h1 1.5 150 70.5 pin 8 116 -108 -116 -108
8:00 PM ET Temple Rutgers total h1 1.5 150 70.5 5d 6 116 -110 -116 -110
8:05 PM ET Drake Evansville ml h1 7 136 0 5d 4 -214 -210 214 175
8:00 PM ET Northern Iowa Bradley total h1 12 133 62 5d 3 113 -110 -113 -110
6:00 PM ET Cincinnati SMU ml h1 8 125.5 0 5d 2 -242 -240 242 200
现在我能想到的唯一方法是逐行打印到 txt 文件,循环遍历数据框(按边缘列排序),对于每个条目,我可以在数据框的其余部分中搜索另一个条目相同的 f_name、d_name、type_bet、sec 并打印它,然后从数据框中删除它。但我认为有更好的方法吗?
【问题讨论】: