Compare samples with grouped data - can t-test be used? If I have to compare the height of two samples but the data provided are grouped, e.g.
Height        SampleA SampleB
[150-160) cm     10      7
[160-170) cm     12      4
[170-180) cm      7     20

is it valid to use the t-test or should the ranges of height be treated as categories of a nominal variable?
I know you can compute e.g. the mean using the midpoints and the frequencies but is it ok to use the midpoints to check if the distributions are normal?
 A: You could use an ordered logistic (i.e., ordinal) regression, using height as the dependent variable and what sample it came from as the independent variable.
Let height be a categorical (i.e., factor) variable, where:


*

*1 = [150-160) cm

*2 = [160-170) cm

*3 = [170-180) cm


I assume the numbers under SampleA and SampleB are frequency counts. To create this data frame in R, you can do:
sample_a <- c(rep(1, 10), rep(2, 12), rep(3, 7))
sample_b <- c(rep(1, 7), rep(2, 4), rep(3, 20))
dat <- data.frame(
  height = as.factor(c(sample_a, sample_b)),
  sample = factor(c(rep("a", length(sample_a)), rep("b", length(sample_b))))
)

This replicates the table you provided:
> table(dat$height, dat$sample)

     a  b
  1 10  7
  2 12  4
  3  7 20

Then, you can use the clm function from the ordinal package to do the regression:
> library(ordinal)
> summary(clm(height ~ sample, data = dat))
formula: height ~ sample
data:    dat

 link  threshold nobs logLik AIC    niter max.grad cond.H 
 logit flexible  60   -60.78 127.56 4(0)  2.27e-10 1.1e+01

Coefficients:
        Estimate Std. Error z value Pr(>|z|)  
sampleb   1.2871     0.5083   2.532   0.0113 *
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Threshold coefficients:
    Estimate Std. Error z value
1|2  -0.4104     0.3499  -1.173
2|3   0.8288     0.3649   2.271

Ordinary least squares regression (in this case, a t-test) cannot be used here, as you do not have a continuous dependent variable—it is an ordered category by nature. Even if the histogram looked normal, it still wouldn't be normally distributed, as the dependent variable is still a category.
There are many books on generalized linear models that will tell you about ordinal regression, but the best introduction I think is a chapter from The Oxford Handbook of Quantitative Methods, Volume II: Statistical Analysis. It is Chapter 3, "Generalized Linear Models," by Coxe, West, & Aiken.
A: I agree with the answer by @MarkWhite.
However, because the design in the question is simple, you could also use a test designed for a table with one categorical variable and one ordinal variable, such as the Cochran-Armitage test.
In R, this kind of test is implemented as a permutation test in the coin package.  Note that in this test you have to indicate the thresholds of the categories, in the scores option. Describing these thresholds as "symmetric" or "equidistant" is an option in the clm function indicated by @MarkWhite.
There's probably no advantage to using this approach rather than ordinal regression, except that it may be more convenient for data already arranged in a table.
### Adapted from:
###  http://rcompanion.org/handbook/H_09.html

if(!require(coin)){install.packages("coin")}

Input =(
"Sample   SampleA SampleB
Height
Low      10      7
Medium   12      4
High      7     20
")

Tabla = as.table(read.ftable(textConnection(Input)))

Tabla

sum (Tabla)

prop.table(Tabla,
           margin = 2)   ### proportion in each column
###
###  Proportion in each in column
###       Sample
### Height     SampleA   SampleB
###   Low    0.3448276 0.2258065
###   Medium 0.4137931 0.1290323
###   High   0.2413793 0.6451613

library(coin)

spineplot(t(Tabla))


library(coin)

Test = chisq_test(Tabla,
              scores = list("Height" = c(-1, 0, 1)))

Test

### Asymptotic Linear-by-Linear Association Test
###
### data:  Sample by Height (Low < Medium < High)
### Z = -2.4092, p-value = 0.01599
### alternative hypothesis: two.sided

