How to calculate amplitude of each class in R?

Asked

Viewed 730 times

2

I have the following variable in R

    set.seed(7)
valor <- round(runif(35, min=30, max=100), 2)

I want to calculate the amplitude (maximum value - minimum value) for each class of my data. To calculate the maximum amplitude (of all classes), I did: diff(range(valor))

However, I do not know how to do for each of the classes, by the method of Sturges(nclass.Sturges) I got q have 7 classes.

1 answer

1

By definition, the classes of a histogram constructed through the Sturges method will always have the same amplitude. Therefore, it is sufficient to take the total amplitude of the sample, given by diff(range(valor)), and divide it by the number of classes, given by grDevices::nclass.Sturges(valor). So we have

set.seed(7)
valor <- round(runif(35, min=30, max=100), 2)
diff(range(valor))/grDevices::nclass.Sturges(valor)
9.88

Browser other questions tagged

You are not signed in. Login or sign up in order to post.