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
10
votes
2 answers

Adding property to the request using Node and Express

I have a MEAN application, and I'm handling authentication using passport. What I want to do is exactly what happens to the user on the passport, which can be accessed from the request like req.user. I have not found any solutions to reach that…
Joao
  • 268
  • 1
  • 2
  • 9
10
votes
2 answers

Calculating local means in a 1D numpy array

I have 1D NumPy array as follows: import numpy as np d = np.array([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]) I want to calculate means of (1,2,6,7), (3,4,8,9), and so on. This involves mean of 4 elements: Two consecutive elements and two…
Borys
  • 1,323
  • 6
  • 16
  • 40
10
votes
3 answers

Dealing with NAs when calculating mean (summarize_each) on group_by

I have a data frame md: md <- data.frame(x = c(3,5,4,5,3,5), y = c(5,5,5,4,4,1), z = c(1,3,4,3,5,5), device1 = c("c","a","a","b","c","c"), device2 = c("B","A","A","A","B","B")) md[2,3] <- NA md[4,1] <- NA md I want to calculate means by…
user2323534
  • 585
  • 1
  • 6
  • 18
10
votes
2 answers

Panda dataframe conditional .mean() depending on values in certain column

I'm trying to create a new column which returns the mean of values from an existing column in the same df. However the mean should be computed based on a grouping in three other columns. Out[184]: YEAR daytype hourtype scenario option_value …
tpapz
  • 107
  • 1
  • 1
  • 8
10
votes
3 answers

Datetime objects with pandas mean function

I am new to programming so I apologize in advance if this question does not make any sens. I noticed that when I try to calculate the mean value of a pandas data frame with a date time object formatted like this: datetime.datetime(2014, 7, 10), it…
Avelina
  • 103
  • 1
  • 1
  • 5
10
votes
5 answers

Find and replace missing values with row mean

I have a data frame with NAs and I want to replace the NAs with row means c1 = c(1,2,3,NA) c2 = c(3,1,NA,3) c3 = c(2,1,3,1) df = data.frame(c1,c2,c3) > df c1 c2 c3 1 1 3 2 2 2 1 1 3 3 NA 3 4 NA 3 1 so that > df c1 c2 c3 1 1 3 …
Brian
  • 349
  • 4
  • 16
9
votes
6 answers

How to average over a cell-array of arrays?

I have a cell array c of equal-sized arrays, i.e. size(c{n}) = [ m l ... ] for any n. How can I get the mean values (averaging over the cell array index n) for all array elements in one sweep? I thought about using cell2mat and mean but the former…
Tobias Kienzler
  • 25,759
  • 22
  • 127
  • 221
9
votes
2 answers

How to get the mean for a whole dataframe instead of columns?

How do I get the mean for all of the values (except for NaN) in a pandas dataframe? pd.DataFrame.mean() only gives the means for each column (or row, when setting axis=1), but I want the mean over the whole thing. And df.mean().mean() isn't really…
JC_CL
  • 2,346
  • 6
  • 23
  • 36
9
votes
3 answers

Pandas.mean() TypeError: Could not convert to numeric

I am working on a project where I imported data from SQL into a pandas DataFrame. This seems to go swimmingly, but when I take the pandas.mean() it throws a TypeError saying that a concatenated list of the values cannot be converted to numeric (see…
Tom Mori
  • 131
  • 1
  • 1
  • 3
9
votes
2 answers

Plotting means as a line plot onto a scatter plot with ggplot

I have this simple data frame holding three replicates (value) for each factor (CT). I would like to plot it as geom_point and than the means of the point as geom_line. gene <-…
Toke Duce Krogager
  • 207
  • 2
  • 3
  • 6
9
votes
2 answers

mean( ,na.rm=TRUE) still returns NA

I'm very new to R (moving over from SPSS). I'm using RStudio on a Mac running Mavericks. Please answer my question in words of 2 syllables as this is my first real attempt at anything like this. I've worked through some basic tutorials and can…
Rnovice
  • 125
  • 1
  • 2
  • 6
9
votes
1 answer

How to unscale the coefficients from an lmer()-model fitted with a scaled response

I fitted a model in R with the lmer()-function from the lme4 package. I scaled the dependent variable: mod <- lmer(scale(Y) ~ X + (X | Z), data = df, REML = FALSE) I look at the…
lord.garbage
  • 5,884
  • 5
  • 36
  • 55
9
votes
2 answers

Block mean of numpy 2D array

I want to find block mean of a 2D array in NumPy. For simplicity, let us assume that the array is as follows: array([[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]]) I want to divide this…
Nik
  • 5,515
  • 14
  • 49
  • 75
9
votes
4 answers

Efficiently compute mean and standard deviation from a frequency table

Suppose I have the following frequency table. > print(dat) V1 V2 1 1 11613 2 2 6517 3 3 2442 4 4 687 5 5 159 6 6 29 # V1 = Score # V2 = Frequency How can I efficiently compute the Mean and standard deviation? Yielding: SD=0.87…
neversaint
  • 60,904
  • 137
  • 310
  • 477
8
votes
3 answers

Mean of non-diagonal elements of each row numpy

I essentially have a confusion matrix of size n x n with all my diagonal elements being 1. For every row, I wish to calculate its mean, excluding the 1, i.e. excluding the diagonal value. Is there a simple way to do it in numpy? This is my current…
OlorinIstari
  • 537
  • 5
  • 20