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

Alaios alaios at yahoo.com
Thu Nov 5 10:49:55 CET 2015


Thanks.That is what I want. It is more that I do not know how to read factors that these two functions return
Browse[1]> y
$`13.6954016405008`
[1] (13.2,115]
Levels: (13.2,115] (115,217] (217,318] (318,420] (420,522]

$`88.5092280867206`
[1] (13.2,115]
Levels: (13.2,115] (115,217] (217,318] (318,420] (420,522]

$`137.931810364616`
[1] (115,217]
Levels: (13.2,115] (115,217] (217,318] (318,420] (420,522]

 str(y)
List of 30
 $ 13.6954016405008: Factor w/ 5 levels "(13.2,115]","(115,217]",..: 1
 $ 88.5092280867206: Factor w/ 5 levels "(13.2,115]","(115,217]",..: 1
 $ 137.931810364616: Factor w/ 5 levels "(13.2,115]","(115,217]",..: 2
 $ 138.559590072838: Factor w/ 5 levels "(13.2,115]","(115,217]",..: 2
 $ 143.085897171535: Factor w/ 5 levels "(13.2,115]","(115,217]",..: 2
 $ 177.678839068735: Factor w/ 5 levels "(13.2,115]","(115,217]",..: 2
 $ 177.819693807561: Factor w/ 5 levels "(13.2,115]","(115,217]",..: 2
 $ 184.752000138622: Factor w/ 5 levels "(13.2,115]","(115,217]",..: 2
 $ 211.255591076421: Factor w/ 5 levels "(13.2,115]","(115,217]",..: 2
 $ 238.951618624679: Factor w/ 5 levels "(13.2,115]","(115,217]",..: 3
 $ 241.609050762905: Factor w/ 5 levels "(13.2,115]","(115,217]",..: 3
 $ 252.528297510773: Factor w/ 5 levels "(13.2,115]","(115,217]",..: 3 3 3
 $ 254.643586371518: Factor w/ 5 levels "(13.2,115]","(115,217]",..: 3

I need to be able to keep the items within their groups and at the same time to keep the label of the group so to be able to use it for plotting purposes.
How I can do that?RegardsAlex
 


     On Wednesday, November 4, 2015 11:20 PM, Rolf Turner <r.turner at auckland.ac.nz> wrote:
   

 
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


  
	[[alternative HTML version deleted]]



More information about the R-help mailing list