0

From a data.frame:

RowColFovCellID 1Feret
001001000      1.1      
001002000      0.3      
001002000      0.2      
001003000      1.5      
001001000      3.4      
001002000      2.4      
003003001      0.7      
001001000      3.6      

I would like to bin data by a unique ID and show the results as new columns in a dataframe, for example:

RowColFovCellID0-11-22-33-44-5
001001000      0      1      0      2      0      
001002000      2      0      1      0      0      
001003000      0      1      0      0      0      
003003001      1      0      0      0      0      

I have tried using ddply and cut but not managed it so far.

Thanks

A5C1D2H2I1M1N2O1R2T1
  • 190,393
  • 28
  • 405
  • 485
William Grimes
  • 675
  • 2
  • 11
  • 29
  • 1
    Regarding binning, what was wrong with [@Martín Bel's `cut` answer](http://stackoverflow.com/questions/20851362/r-binning-dataset-and-surface-plot/20851667#20851667) to one of your previous question about binning on similar data? – Henrik Apr 09 '14 at 07:56

2 Answers2

0

I would suggest you take a two-step approach to accomplish what you are aiming to do. First, create an additional column in your data.frame in which you classify the observed values in the variable 'Feret'. Then second, you use xtable from the xtable package to create the cross table you show above.

Jochem
  • 3,295
  • 4
  • 30
  • 55
0

You mentioned you tried cut, but don't show what you tried.

This seems to be a straightforward table problem. Assuming your data.frame is called "mydf" and your columns are "RowColFovCellID" and "Feret", try:

table(mydf$RowColFovCellID, cut(mydf$Feret, 0:5))
# 
#         (0,1] (1,2] (2,3] (3,4] (4,5]
# 1001000     0     1     0     2     0
# 1002000     2     0     1     0     0
# 1003000     0     1     0     0     0
# 3003001     1     0     0     0     0
A5C1D2H2I1M1N2O1R2T1
  • 190,393
  • 28
  • 405
  • 485