I have to organize a thousand data that is in a text file in 10 categories, I have already managed to import the data into R, and create the intervals but I do not know how to organize the data in these intervals, what I need to know is how much data is there in each interval . I hope you can help me.
# establecer el directorio de trabajo
setwd(dir = "C:/Users/DELL/Documents/Texto/")
# importar base de datos en el objeto llamado base_de_datos
base_de_datos <- read.table(file = "taller03_datos.txt")
# extraer los valores de la varible en el objeto llamado cal
cal <- base_de_datos$V1
# tamaño de la muestra
n <- length(cal)
#Máximo y Mínimo
Max <- max(cal)
Min <- min(cal)
#Rango
R <- Max - Min
#promedio aritmético
M <- mean(cal)
#amplitud del intervalo
a <- R/10
#intervalos
li <- seq(from=Min, to= Max-a, by=a)
ls <- seq(from=Min+a, to= Max, by=a)
# Marca de clase
Mc <- (li+ls)/2
# Frecuencia absoluta
#Tabla
tabla <- cbind(li,ls)
If I understand you correctly, I think you have complicated your life, what you are looking for is the frequency for the 10 equidistant intervals. Let's imagine a variable with 1000 observations that can have different values:
Simply, we can use
cut()
to "cut" the sample into a desired number of portions, then yes, withtable()
we can count how many values each portion takes:To divide a probability distribution into "equal" groups, do we calculate the quantiles, in this case, the deciles? since we want to divide the distribution into 10 parts, which will be very useful for making a box plot for similar groups and observing the outliers.
quantile(Table$Variable,prob=c(0,0.10,0.20,0.30,0.40,0.50,0.60,0.70,0.80,0.90)
#on the other hand, if we divide the distribution into 5 parts, we will have the quintiles. Useful for making 5 groups of data.
quantile(Table$Variable,prob=c(0,0.20,0.4,0.6,0.8,1))
#Another important grouping, which has to do with sigma values
quantile(Table$Variable,prob=c(0.6826,0.9546,0.9973,0.999937,0.9999943,0.99999998))
I don't know if this is exactly what you are looking for.