I have the following data frame in R:
> str(x2)
'data.frame': 262064 obs. of 15 variables:
$ ykod : int 99 99 99 99 99 99 99 99 99 99 ...
$ yad : Factor w/ 38 levels "BAKUGAN","BARBIE",..: 2 2 2 2 2 2 2 2 2 2 ...
$ per : Factor w/ 3 levels "2 AYLIK","3 AYLIK",..: 3 3 3 3 3 3 3 3 3 3 ...
$ donem: int 201106 201106 201106 201106 201106 201106 201106 201106 201106 201106 ...
$ sayi : int 201106 201106 201106 201106 201106 201106 201106 201106 201106 201106 ...
$ mkod : int 359 361 362 363 366 849 850 1505 1506 1525 ...
$ mad : Factor w/ 9529 levels " Hilal Gida ",..: 4473 3322 9360 7169 9359 9290 8903 6057 6055 6620 ...
$ mtip : Factor w/ 27 levels "Abone Bürosu ",..: 18 18 18 18 18 2 2 10 10 2 ...
$ kanal: Factor w/ 2 levels "OB","SS": 2 2 2 2 2 2 2 1 1 2 ...
$ bkod : int 110006 110006 110006 110006 110006 110006 110006 110006 110006 110006 ...
$ bad : Factor w/ 208 levels "4. Levent","500 Evler",..: 25 25 25 25 25 25 25 25 25 25 ...
$ bolge: Factor w/ 12 levels "Adana Şehiriçi",..: 7 7 7 7 7 7 7 7 7 7 ...
$ sevk : int 5 2 2 2 10 4 3 13 32 4 ...
$ iade : int 0 2 1 2 4 3 2 0 8 4 ...
$ satis: int 5 0 1 0 6 1 1 13 24 0 ...
Is it possible to rearrange this data frame like an Excel PivotTable? For example, I want to take ykod = 99
and create a new data frame with new rows and columns as follows:
donem=201106 donem=201107 donem=201108
Row# mkod mad sevk iade satis sevk iade satis sevk iade satis
---- ---- --- ---- ----- ---- ---- ---- ---- ---- ----- ----
1 654 Abc 10 2 8 15 12 3 8 3 5
2 721 Def
.
.
4345
Of course, the column names in the above example should be recreated, for example, as 201106_sevk
, 201106_iade
, 201106_satis
, so and so forth.