Questions tagged [mean]

The arithmetic mean (or simply the mean or average when the context is clear) is the central tendency of a collection of numbers. The mean is calculated as the sum of the numbers divided by the size of the collection.

The arithmetic mean, or simply the mean or when the context is clear, is the central tendency of a collection of numbers. The mean is calculated as the sum of the numbers divided by the size of the collection. Besides the arithmetic mean, the geometric mean and the harmonic mean can be calculated as well.

Means apply an equal weight to every member of a collection of numbers. This feature makes means not robust to outlier members. cf.

Source: Wikipedia

3925 questions
14
votes
2 answers

Summarize data.table by group

I am working with a huge data table in R containing monthly measurements of temperature for multiple locations, taken by different sources. The dataset looks like this: library(data.table) # Generate random data: loc <- 1:10 dates <-…
thiagoveloso
  • 2,537
  • 3
  • 28
  • 57
14
votes
4 answers

Decrease array size by averaging adjacent values with numpy

I have a large array of thousands of vals in numpy. I want to decrease its size by averaging adjacent values. For example: a = [2,3,4,8,9,10] #average down to 2 values here a = [3,9] #it averaged 2,3,4 and 8,9,10 together So, basically, I have n…
Adam Haile
  • 30,705
  • 58
  • 191
  • 286
14
votes
1 answer

haskell - Average floating point error using QuickCheck

I am using QuickCheck-2.5.1.1 to do QA. I am testing two pure functions gold :: a -> Float and f :: a -> Float, where a instances Arbitrary. Here gold is a reference calculation and f is a variation I am optimizing. To date, most of my tests using…
Matt W-D
  • 1,605
  • 2
  • 19
  • 22
14
votes
4 answers

Calculating Mean of arrays with different lengths

Is it possible to calculate the mean of multiple arrays, when they may have different lengths? I am using numpy. So let's say I have: numpy.array([[1, 2, 3, 4, 8], [3, 4, 5, 6, 0]]) numpy.array([[5, 6, 7, 8, 7, 8], [7, 8, 9, 10, 11,…
hjweide
  • 11,893
  • 9
  • 45
  • 49
13
votes
3 answers

Function that converts a vector of numbers to a vector of standard units

Is there a function that given a vector of numbers, returns another vector with the standard units corresponding to each value? where standard unit: how many SDs a value is + or - from the mean Example: x <- c(1,3,4,5,7) # note: mean = 4, sd =…
jd.
  • 4,543
  • 7
  • 34
  • 40
13
votes
3 answers

How to fill nan values with rolling mean in pandas

I have a dataframe which contains nan values at few places. I am trying to perform data cleaning in which I fill the nan values with mean of it's previous five instances. To do so, I have come up with the…
VaM999
  • 453
  • 1
  • 9
  • 23
13
votes
5 answers

How to add a line in boxplot?

I would like to add lines between "mean" in my boxplot. My code: library(ggplot2) library(ggthemes) Gp=factor(c(rep("G1",80),rep("G2",80))) Fc=factor(c(rep(c(rep("FC1",40),rep("FC2",40)),2))) Z <-factor(c(rep(c(rep("50",20),rep("100",20)),4))) Y <-…
Ph.D.Student
  • 704
  • 6
  • 27
13
votes
1 answer

"circular" mean in R

Given a dataset of months, how do I calculate the "average" month, taking into account that months are circular? months = c(1,1,1,2,3,5,7,9,11,12,12,12) mean(months) ## [1] 6.333333 In this dummy example, the mean should be in January or December. …
generic_user
  • 3,430
  • 3
  • 32
  • 56
13
votes
8 answers

What's the quickest way to get the mean of a set of numbers from the command line?

Using any tools which you would expect to find on a nix system (in fact, if you want, msdos is also fine too), what is the easiest/fastest way to calculate the mean of a set of numbers, assuming you have them one per line in a stream or file?
Anthony
  • 1,306
  • 4
  • 13
  • 23
13
votes
6 answers

R - min, max and mean of off-diagonal elements in a matrix

I have like a matrix in R and I want to get: Max off - diagonal elements Min off – diagonal elements Mean off –diagonal elements With diagonal I used max(diag(A)) , min(diag(A)) , mean(diag(A)) and worked just fine But for off-diagonal I tried…
amhemad ahmad
  • 195
  • 2
  • 2
  • 6
12
votes
4 answers

Weighted average using NA weights

a=c(1,2,NA,4) b=c(10,NA,30,40) weighted.mean(a,b,na.rm = T) The above code gives me NA as the answer, I think na.rm only ignores the NA values in vector a and not b. How can I ignore the NA in vector b or weights to be specific. I just cannot…
Jain
  • 959
  • 2
  • 13
  • 31
12
votes
5 answers

Combine multiple data frames and calculate average

I have three data frames as below. I wish to combine them into one data frame according to Lon & Lat, and average the 3 values for each 'cell'. I have read this (calculate average over multiple data frames) and attempted to utilise aggregate but to…
Darren J
  • 503
  • 2
  • 5
  • 16
12
votes
2 answers

Plot mean and standard deviation by category

I'm trying to plot a plot with mean and sd bars by three levels of a factor. (After two hours of searching on the internet, then checking the Rbook and Rgraphs book I'm still not finding the answer. I think this is because it is a very simple…
Maria
  • 233
  • 3
  • 4
  • 8
12
votes
5 answers

average between duplicated rows in R

I have a data frame df with rows that are duplicates for the names column but not for the values column: name value etc1 etc2 A 9 1 X A 10 1 X A 11 1 X B 2 1 Y C 40…
biohazard
  • 2,017
  • 10
  • 28
  • 41
12
votes
2 answers

how can I choose a random number but with a normal probability distribution in PHP?

In php, how can I generate a a random number assuming a normal distribution with a specific mean and standard devaition?
Maggie
  • 357
  • 4
  • 11