Determining if a group number of members is statistically different from another in R So, I have a large DF with a survey in which I need compare the n numbers between crosstab with categorical variables, this is a made up example.
sex <- c("male", "male", "male", "female", "male", "female", "male", 
         "female", "female", "male")

quintile <- c("first", "second", "third", "second", "fifth", "fifth", 
              "second", "fourth", "fourth", "third")

df <- data.frame(sex, quintile, stringsAsFactors = T)

So I do a crosstab:
table(df$quintile, df$sex)
        
         female male
  fifth       1    1
  first       0    1
  fourth      2    0
  second      1    2
  third       0    2

I want to know if the number of females in the first quintile is statitiscally different from the number of males, and also, if needed, if the total number of people in the first quintile (the sum of males and females) is statistically different from the the total number of people in the third quintile (or any other).
At first I thought prop.testwould make the trick, but I'm not really sure about it, and it wouldn't allow me to compare the totals anyway, at least not in the way I wanted.
 A: First, create a bit more data than you provided:
set.seed(42)
sex <- sample(c("male", "female"), 100, replace=TRUE)
quints <- c("first", "second", "third", "fourth", "fifth")
quintile <- rep(c("first", "second", "third", "fourth", "fifth"), 20)
quintile <- factor(quintiles, levels=quints)
df <- data.frame(sex, quintles)
(tbl <- xtabs(~quintile+sex, df))
#         sex
# quintile female male
#   first      13    7
#   second      9   11
#   third      12    8
#   fourth     12    8
#   fifth      10   10

Now use prop.test to test the null hypothesis of no difference between the sexes:
apply(tbl, 1, function(x) prop.test(matrix(x, 1)))
# $first
# 
#   1-sample proportions test without continuity correction
# 
# data:  matrix(x, 1), null probability 0.5
# X-squared = 0, df = 1, p-value = 1
# alternative hypothesis: true p is not equal to 0.5
# 95 percent confidence interval:
#  0.299298 0.700702
# sample estimates:
#   p 
# 0.5 
# 
#    .  .  .  .  .
# 
# $fifth
# 
#   1-sample proportions test with continuity correction
# 
# data:  matrix(x, 1), null probability 0.5
# X-squared = 0.45, df = 1, p-value = 0.5023
# alternative hypothesis: true p is not equal to 0.5
# 95 percent confidence interval:
#  0.1997709 0.6358833
# sample estimates:
#   p 
# 0.4 

A: I agree with Whuber's comment. Along those lines, a p.value assumes some
underlying distribution for the data before calculating the quintiles.  ,
May be we can assume to have a uniform distribution in a range of values and  no difference between males and females. From there we can generate samples, calculate the quintiles, count number of males and females, calculate the difference, and get a p-value. In this case (as Whuber stated), quintiles will change with the sample.
Overall, I feel there is some better way but we need to know more about your data
