[R] [FORGED] Re: merging-binning data

Rolf Turner r.turner at auckland.ac.nz
Wed Nov 4 23:20:06 CET 2015


I have been vaguely following this thread and have become very confused 
given the complications that seem to have appeared.

The original question was:

>>>>> On Tue, Nov 3, 2015 at 10:47 AM, Alaios via R-help <r-help at r-project.org> wrote:
>>>>>> Dear all,I am not exactly sure on what is the proper name of what I am trying to do.
>>>>>> I have a vector that looks like

Actually you appear to have a 32 x 1 *matrix* (NOT the same thing!) that 
looks like:

>>>>>>    binDistance
>>>>>>              [,1]
>>>>>>    [1,] 238.95162
>>>>>>    [2,] 143.08590
>>>>>>    [3,]  88.50923
>>>>>>    [4,] 177.67884
>>>>>>    [5,] 277.54116
>>>>>>    [6,] 342.94689
>>>>>>    [7,] 241.60905
>>>>>>    [8,] 177.81969
>>>>>>    [9,] 211.25559
>>>>>> [10,] 279.72702
>>>>>> [11,] 381.95738
>>>>>> [12,] 483.76363
>>>>>> [13,] 480.98841
>>>>>> [14,] 369.75241
>>>>>> [15,] 267.73650
>>>>>> [16,] 138.55959
>>>>>> [17,] 137.93181
>>>>>> [18,] 184.75200
>>>>>> [19,] 254.64359
>>>>>> [20,] 328.87785
>>>>>> [21,] 273.15577
>>>>>> [22,] 252.52830
>>>>>> [23,] 252.52830
>>>>>> [24,] 252.52830
>>>>>> [25,] 262.20084
>>>>>> [26,] 314.93064
>>>>>> [27,] 366.02996
>>>>>> [28,] 442.77467
>>>>>> [29,] 521.20323
>>>>>> [30,] 465.33071
>>>>>> [31,] 366.60582
>>>>>> [32,]  13.69540

A later addendum to the question indicated that the OP wanted labels for 
the result consisting of the endpoints of the intervals into which the 
data were subdivided.  Unless I am misunderstanding, this is trivial to 
accomplish using cut() and split():

x <- c(238.95162, 143.0859, 88.50923, 177.67884, 277.54116, 342.94689,
241.60905, 177.81969, 211.25559, 279.72702, 381.95738, 483.76363,
480.98841, 369.75241, 267.7365, 138.55959, 137.93181, 184.752,
254.64359, 328.87785, 273.15577, 252.5283, 252.5283, 252.5283,
262.20084, 314.93064, 366.02996, 442.77467, 521.20323, 465.33071,
366.60582, 13.6954)

f <- cut(x,5)

y <- split(x,f)

y

$`(13.2,115]`
[1] 88.50923 13.69540

$`(115,217]`
[1] 143.0859 177.6788 177.8197 211.2556 138.5596 137.9318 184.7520

$`(217,318]`
  [1] 238.9516 277.5412 241.6090 279.7270 267.7365 254.6436 273.1558 
252.5283
  [9] 252.5283 252.5283 262.2008 314.9306

$`(318,420]`
[1] 342.9469 381.9574 369.7524 328.8779 366.0300 366.6058

$`(420,522]`
[1] 483.7636 480.9884 442.7747 521.2032 465.3307


Is this not the result that you want?  If not, what *is* the result that 
you want?

cheers,

Rolf Turner

-- 
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276



More information about the R-help mailing list