Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I calculate the mean of a column

Anyone know how can I calculate the mean of one these columns (on linux)??

sda               2.91    20.44    6.13    2.95   217.53   186.67    44.55     0.84   92.97 sda               0.00     0.00    2.00    0.00    80.00     0.00    40.00     0.22  110.00  sda               0.00     0.00    2.00    0.00   144.00     0.00    72.00     0.71  100.00  sda               0.00    64.00    0.00    1.00     0.00     8.00     8.00     2.63   10.00 sda               0.00     1.84    0.31    1.38    22.09   104.29    74.91     3.39 2291.82  sda               0.00     0.00    0.00    0.00     0.00     0.00     0.00     0.00    0.00   

For example: mean(column 2)

like image 217
Alucard Avatar asked Jun 26 '10 02:06

Alucard


People also ask

How do you find the mean of a column in a DataFrame?

To calculate the mean of whole columns in the DataFrame, use pandas. Series. mean() with a list of DataFrame columns. You can also get the mean for all numeric columns using DataFrame.

How do you calculate mean for a column in R?

To calculate the average of a data frame column in R, use the mean() function. The mean() function takes the column name as an argument and calculates the mean value of that column.

Where can I find mean pandas?

To calculate a mean of the Pandas DataFrame, you can use pandas. DataFrame. mean() method. Using the mean() method, you can calculate mean along an axis, or the complete DataFrame.

How do I get the mean of multiple columns in R?

To find the mean of multiple columns based on multiple grouping columns in R data frame, we can use summarise_at function with mean function.


1 Answers

Awk:

awk '{ total += $2 } END { print total/NR }' yourFile.whatever 

Read as:

  • For each line, add column 2 to a variable 'total'.
  • At the end of the file, print 'total' divided by the number of records.
like image 130
porges Avatar answered Sep 25 '22 13:09

porges