如何从列表中将顶部值提取到R中的新列中

时间:2017-06-02 01:51:29

标签: r

以下是我的数据示例:

Country 2015Items   2015Value
ABC Wool    3552055979
ABC Apple   1775773427
ABC Petrol  2752962693
ABC Fridge  1335506929
ABC Tables  1291665383
ABC Chairs  1027089628
ABC Bed 1290351671
ABC House   986436657
ABC Car 551879018
ABC Computer    584943655
ABC Food    814941472
ABC TV  973840104
ABC Mobilephone 726470080
ABC Clothes 717457949
ABC Shoes   721929032
ABC Hospital    541655398
ABC Rent    353607422
ABC Taxi    471133115
ABC Internet    277022661
ABC Electricity 512012127
BBC Car 1420288322
BBC Computer    522551411
BBC Food    404371232
BBC Wool    213157046
BBC Apple   187686888
BBC Petrol  151166773
BBC TV  106387682
BBC Mobilephone 157454626
BBC Clothes 127634267
BBC Shoes   57014632
BBC Fridge  79559962
BBC Tables  87964468
BBC Chairs  78008662
BBC Bed 55030418
BBC House   67562167
BBC Internet    73462493
BBC Electricity 108313631
BBC Hospital    38170134
BBC Rent    50490622
BBC Taxi    57223118
FFG Fridge  740076042
FFG Tables  1015329163
FFG Chairs  1227821602
FFG Bed 296851335
FFG House   420658913
FFG Internet    291803668
FFG Electricity 125184444
FFG Hospital    181314099
FFG Rent    121260638
FFG Taxi    110684353
FFG Wool    126284645
FFG Apple   82883226
FFG Petrol  93763419
FFG Fridge  80797162
FFG Tables  82398328
FFG Chairs  62106203
FFG Bed 48549422
FFG House   55485333
FFG Car 68629733
FFG Computer    45434889

我想按2015年值列对每个国家/地区的数据进行排序,然后提取数据以生成此输出:

Country 2015Value1stvalue   2015Value2ndvalue   2015Value3rdvalue       ….. 2015Value20thvalue  2015Items1st    2015Items2nd    2015Items3rd    …   2015Items20th
ABC 3552055979  2752962693  1775773427      ….. 277022661   Wool    Petrol  Apple   …   Internet
BBC 1420288322  522551411   404371232       ….. 38170134    Car Computer    Food    …   Hospital
FFG 1227821602  1015329163  740076042       ….. 45434889    Chairs  Tables  Fridge  …   Computer

我已经使用了这个代码,但是我必须做20次。有更快的方法吗?我只是R的新人。谢谢你。

这是我的代码:

checkslice <- (slice(run_select,1))[,3:9]
checkslice <- cbind(checkslice,(slice(run_select,2))[,4:9])

0 个答案:

没有答案