r - factor with 6 levels out of a continuous variable -
I have a continuous change of frequency which is from 0 to 6.115053. I need to divide it into 6 levels, my analysis will be more readable in this way.
I have tried:
frequency.new & lt; - hist (all instances, 6, plot = FALSE) all frequency & lt; - as.factor (frequency.new) but I get an error that I do not understand:
error in sort.list (y): 'X' should be atom for 'sort.list' Do you have to say 'sort' on a list? Can anyone help me?
Thanks a lot!
Katrina
You must include cut () Should look at the function. You should keep in mind the last line of your answer (in bold). & gt; Set.seed (42) & gt; Cut (Ranif (50), 6) [0.8] (0.825) 0.99 (0.825,0.9 9) (0.167,0.332) (0.825,0.99) [5] (0.496,0.661) (0.496,0.661) (0.661 , 0.825) (0.00296,0.167) [9] (0.496,0.661) (0.661.0.825) (0.332,0.496) (0.661.0.825) [13] (0.825,0.99) (0.167,0.332) (0.332,0.496) (0.825,0.99) [17] (0.825,0.99) (0.00296,0.167) (0.332,0.496) (0.496,0.661) [21] (0.825,0.99) (0.00296,0.167) (0.825,0.9.9) ) (0.825,0.9 9) [25] (0.00296,0.167) (0.496,0.661) (0.332,0.496) (0.825,0.99) [29] (0.332,0.496) (0.825,0.99) (0.661,0.825 ) (0.661.0.825) [33] (0.332.0.496) (0.661.0.825) (0.00296,0.167) (0.825,0.99) [37] (0.00296,0.167) (0.167.0.332) (0.825,0.99) ( 0.496,0.661) [41] (0.332,0.496] (0.332, 0.496] (0.00296,0.167) (0.825,0.99) [45] (0.332,0.496) (0.825,0.99) (0.825,0.99) (0.496 , 0.661) [49 (0.825,0.99) (0.496,0.661) 6 levels: (0.00296,0.167) (0.167.0.332) (0.332,0.496) ... (0.825,0.99) cut () returns an index factor Of these, in this case, 6 groups have seen drops data. It's just a simple SP equal intervals of what to do on the extreme Lita intervals data limit in 6 groups, for details? Read the cut . Due because your code is failing because the object hist () > is a list that is too large in your data: < Code> & gt; Foo & Lt; - Hist (Rainfall (50), Break = 6, Plot = FALSE) & gt; ARF (FU) List of 7 $ breaks: NUM [1: 6] 0 0.2 0.4 0.6 0.8 Number of $ 1: int [1: 5] 12 13 7 13 5 $ Intensity: NUM [1: 5] 1.2 1.3 0.7 1.3 0.5 $ density: num [1: 5] 1.2 1.3 0.7 1.3 0.5 $ mids: num [1: 5] 0.1 0.3 0.5 0.7 0.9 $ xname: chr "runif (50)" $ equidist: logi TRUE - attr (*, " Class ") = Chr" histogram " so that you can convert it to a factor - R does not know how to do this, even notice that hist does not divide the data into 6 groups - it also provides other information to create histogram. Keep that it will generate against the beautiful break, in contrast to cut . If you want these beautiful breaks, we can reproduce that by hist () : & gt; Set.seed (42) & gt; X & LT; - Rooneyf (50) & gt; Brks & lt; - Beautiful (Category (x), n = 6, min.n = 1) & gt; Cut (x, brakes = brakes) [1] (0.8,1) (0.8,1) (0.2,0.4) (0.8,1) (0.6,0.8) (0.4,0.6) (0.6,0.8) [8] ( 0,0.2] (0.6,0.8) (0.6,0.8) (0.4,0.6) (0.6,0.8) (0.8,1) (0.2,0.4) [15] (0.4,0.6) (0.8,1) (0.8, 1] (0,0.2) (0.4,0.6) (0.4,0.6) (0.8,1) [22] (0,0.2) (0.8,1) (0.8,1) (0,0.2) (0.4,0.6) (0.2,0.4) (0.8,1) [0.4] (0.4,0.6) (0.8,1) (0.6,0.8) (0.8,1) (0.2,0.4) (0.6,0.8) (0,0.2) [ 36] (0.8,1) (0,0.2) (0.2,0.4) (0.8,1) (0.6,0.8) (0.2,0.4) (0.4,0.6) [43] (0,0.2) (0.8,1) (0.4,0.6) (0.8,1) (0.8,1) (0.6,0.8) (0.8,1) [50] (0.6,0.8) Level: (0,0.2) (0.2,0.4) (0.4,0.6) (0.6.0.8] (0.8,1) But you should ask yourself why you want to separate your data and do it understand? < / Strong>
Comments
Post a Comment