3
$\begingroup$

I would like to plot the normal distribution for a population of human heights.

My question is how can I input multiple frequencies for the same variable, without writing them out one by one.

e.g. I have 17 instances of 5'10", 20 of 5'11", 4 of 6'.

$\endgroup$
1
  • 1
    $\begingroup$ Have a look at ConstantArray and Join. $\endgroup$ Jan 19, 2013 at 14:18

3 Answers 3

7
$\begingroup$
 Join[
   Table[Quantity["5 feet 11 inches"], {7}], 
   Table[Quantity["5 feet 10 inches"], {20}]
 ]

So there are three things going on here -- we are using Mathematica Version 9 Quantity for things with units, Table to make individual lists of a given length, and Join to concatenate them.

You could also use ConstantArray instead of Table, and various different input forms of "5 feet 10 inches", etc.

$\endgroup$
1
  • $\begingroup$ I found it interesting that "5 feet 11 inches" becomes $5'11"$ which is, in FullForm, Quantity[MixedRadix[5, 11], MixedRadix["Feet", "Inches"] $\endgroup$
    – DavidC
    Jan 19, 2013 at 17:34
2
$\begingroup$
Table[5.10, {17}]

Should do the trick

$\endgroup$
0
2
$\begingroup$
  1. Table is best used for things that change while ConstantArray is optimized for repetition of a single element.

  2. Rather than typing either several times it will be faster to use Apply.

  3. Entering pairs of values is done more quickly with matrix entry tools than nested brackets.

Mathematica graphics

Mathematica graphics

(Flatten or Join can be used to merge sub-lists into one. I am using pre-v9 units in this example.)

All this said there may be a better way to "plot the normal distribution."

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.