1
$\begingroup$

I need to create a table of the Mean Values and Standard Deviations of 18 columns of data from a table. I know how to compute the Mean and Standard Deviation for the different columns, but am unsure how to put the values in to two separate columns on one table with the original column names as different rows. Here's what I've done so far:

Q = Mean[data[[All, {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 
     16, 17, 18, 19}]]]
P = StandardDeviation[
  data[[All, {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 
     18, 19}]]]

I had to use data from columns 2-19 of a table (otherwise I would just have used Mean[data] etc...

Thanks

$\endgroup$

2 Answers 2

4
$\begingroup$

Your question is a bit vague, but I think what you are looking for is Transpose.

 result = Transpose[{First/@ data, Q, P}]

Incidentally, there are many ways you could define the Part ([[ ]]) specifications in your definitions of Q and P, including

Mean[Rest/@data]
Mean[data[[All, 2;; ]] ] 

The second example uses Span, a real convenience.

I am guessing you are a beginner at Mathematica. You might find this question and its answers helpful, especially this one. It is good to get familiar with workhorse functions like Map (/@).

$\endgroup$
1
$\begingroup$

Dataset has a quite a nice way of doing this :

(* Define a random population *)
pop = RandomVariate[NormalDistribution[1, 3], 10^4];

(* pull 4 sets of random samples from it *)
data = Table[RandomSample[pop, 30], {i, 4}];

(* define some column headings you could also just use a list of strings *)
cols = StringJoin["Col ", ToString[#]] & /@ Range[4];

(* map the column headings and the data together into an association then onwards to a dataset *)
ds = AssociationThread[cols -> #] & /@ Transpose[data] // Dataset;

Gives a nicely formatted result

Dataset of columns

Then apply some functions to each dataset column, creating row names for them.

ds[All /* <|"Mean" -> Mean, "SD" -> StandardDeviation|>]

Nice dataset row and column formatting

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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