-2

I´m trying to compare 2 values but before I have to create the intervals. I have no problem with the constant interval, I can go with this:

interval <- seq(4, 44055, by=300)

So I get the same interval from 4 to 44055 with a 300 size.

But I can´t get the value for a different interval. I need to have an interval from 4 to 200, an interval from 201 to 20000 and the last one from 20001 to 44055.

I have the mean of each interval, so I created an interval for each case (int4 <- cut(1,200,by = 5).

But here´s the problem, it says that x and y lengths differ so I cannot get the histograms and the dispersion data. How can I get the the histograms and the dispersion data?

This is the data:

1269.83 -   1 

338 -   1 

1238 -  2 

272 -   1 

1925 -  2 

382 -   8

So I need to divide in 3 groups: one from 1 to 2 elements one from 3 to 7 and the last one with the 8 and beyond (right column, number of salesman). When I get it, I have to make the histograms with the 3 groups against the left column (sales)

Corion
  • 3,855
  • 1
  • 17
  • 27
  • 1
    I don't understand what you are asking. So you actually have some data that you want to look at, or are you just abstractly creating bins? you seem to jump from `seq()` to `cut()` but those are different functions. `cut()` assumes you have some sort of input data you want to bin but you haven't shown any here. It would help to include a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output. – MrFlick Oct 23 '18 at 16:27
  • 2
    Your problem seems convoluted: you start talking about gapped intervals (`c(seq(4,200,by=5),seq(201,20000,by=300),...)`), but then about a problem with different lengths and a histogram. Perhaps you can improve the question by making it more reproducible (to those without access to your console): dput(head(x,20))` (for your data) and more relevant code would be useful. Refs: https://stackoverflow.com/questions/5963269, https://stackoverflow.com/help/mcve, and https://stackoverflow.com/tags/r/info. – r2evans Oct 23 '18 at 16:28
  • Hi! Thanks for answering! – Reto Imposible Oct 23 '18 at 16:29
  • Hi! Thanks for answering! This is the data: 1269.83 1 338.34 1 1238.50 2 272.74 1 1925.82 2 382.39 8 So I need to divide in 3 groups: one from 1 to 2 elements one from 3 to 7 and the last one with the 8 and beyond (right column, number of salesman). When I get it, I have to make the histograms with the 3 groups against the left column (sales) – Reto Imposible Oct 23 '18 at 16:38
  • Your edit to the question still doesn't make it reproducible(see link in MrFlick's comment) or clear to understand what you are asking. You should also check the documentation for `seq()` [here](https://www.rdocumentation.org/packages/base/versions/3.5.1/topics/seq). The `by =` argument defines the number of increments to divide your sequence from 4 to 44055 by. Try printing `interval` in the console to see the result. – Tom Newton Oct 23 '18 at 17:02
  • @RetoImposible please add the x to your edited question! – Shirin Yavari Oct 23 '18 at 17:21

1 Answers1

-1
x<-c(5.6,1269.83, 1, 338.34, 1, 1238.50, 2, 272.74, 1, 1925.82, 2, 382.39, 8)
cut(x, breaks=c(1, 3, 8,Inf), include.lowest=TRUE, right = FALSE)
 #[1] [3,8)   [8,Inf] [1,3)   [8,Inf] [1,3)   [8,Inf] [1,3)   [8,Inf] [1,3)   [8,Inf] [1,3)   [8,Inf] [8,Inf]
 #Levels: [1,3) [3,8) [8,Inf]
Shirin Yavari
  • 626
  • 4
  • 6