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
11
votes
1 answer

Sort boxplot by mean (and not median) in R

I have a simple boxplot, showing the distribution of a score for factor TYPE: myDataFrame = data.frame( TYPE=c("a","a","b","b","c","c"), SCORE=c(1,1,2,3,2,1) ) boxplot( SCORE~TYPE, data=myDataFrame ) The various types are shown in the order they…
Mulone
  • 3,603
  • 9
  • 47
  • 69
11
votes
4 answers

How can I get xtabs to calculate means instead of sums in R?

I have a data frame where each line represents an individual. That data frame has two variables: age and year. I want to make a table of average ages per year. How can I do it? The best I could come up with was xtabs(age ~ year, dataframe), but this…
Waldir Leoncio
  • 10,853
  • 19
  • 77
  • 107
11
votes
8 answers

Means across vectors of different lengths

I have 5 vectors of different lengths a <- c(1) #with length of 1 b <- c(4.4,3.5) #length 2 c <- c(5.6,7.8,6.0) #length 3 d <- c(0.8,6.9,8.8,5.8) #length 4 e <- c(1.8,2.5,2.3,6.5,1.1) #length is 5 I am trying to get the mean of elements across all…
Bella_18
  • 624
  • 1
  • 14
11
votes
2 answers

Finding the mean of nuisance columns in DataFrame error

id gender status dept var1 var2 salary 0 P001 M FT DS 2.0 8.0 NaN 1 P002 F PT FS 3.0 NaN 54.0 2 P003 M NaN AWS 5.0 5.0 59.0 3 P004 F FT AWS NaN 8.0 120.0 4 P005 …
Lima
  • 141
  • 1
  • 1
  • 6
11
votes
6 answers

Error: node_modules/@angular/material/core/common-behaviors/constructor.d.ts:14:64 - error TS1005: ';' expected

My app was working fine until I uninstalled bootstrap and installed angular material instead....Then tried to do ng serve but got this error.. Error: node_modules/@angular/material/core/common-behaviors/constructor.d.ts:14:64 - error TS1005: ';'…
Alish Madhukar
  • 391
  • 1
  • 5
  • 18
11
votes
2 answers

Join Tables in TypeORM & NodeJS

I created to TypeORM Entities Category and Subcategory Category.ts @Entity() export class Category { @PrimaryGeneratedColumn() id: number; @Column() name: string; @Column() description: string; @OneToMany(() => Subcategory,…
DevMachine
  • 553
  • 3
  • 6
  • 15
11
votes
4 answers

Refused to load the font '' because it violates the following Content Security Policy directive default-src ,so default-src is used as a fallback

I am creating a web app using the mean stack in angular 6 but I am getting below error message on the browser console. "Refused to load the font '' because it violates the following Content Security Policy directive: "default-src 'self'".…
Pramod
  • 424
  • 2
  • 7
  • 28
11
votes
7 answers

How to calculate mean of all columns, by group?

I need to get the mean of all columns of a large data set using R, grouped by 2 variables. Lets try it with mtcars: library(dplyr) g_mtcars <- group_by(mtcars, cyl, gear) summarise(g_mtcars, mean (hp)) # Source: local data frame [8 x 3] # Groups:…
Miguel Rozsas
  • 397
  • 2
  • 3
  • 9
11
votes
3 answers

How to get the average of two columns using dplyr?

how to get the average of two columns of a data table using dplyr? For example, if my data if like below: dt <- data.table(A=1:5, B=c(1,4,NA,6,8)) I want to create a new column "Avg" which is the mean of column A and B for each row: dt %>%…
Carter
  • 1,563
  • 8
  • 23
  • 32
11
votes
1 answer

Pandas: Impute NaN's

I have an incomplete dataframe, incomplete_df, as below. I want to impute the missing amounts with the average amount of the corresponding id. If the average for that specific id is itself NaN (see id=4), I want to use the overall average. Below are…
Zhubarb
  • 11,432
  • 18
  • 75
  • 114
11
votes
3 answers

How to get column mean for specific rows only?

I need to get the mean of one column (here: score) for specific rows (here: years). Specifically, I would like to know the average score for three periods: period 1: year <= 1983 period 2: year >= 1984 & year <= 1990 period 3: year >= 1991 This…
TiF
  • 615
  • 2
  • 12
  • 24
11
votes
1 answer

R row means on multiple columns by groups (or unique IDs)

I have a data frame like below (20,000 rows by 49 cols). Each row has a unique name (ID), each ID has 3 repeat reads in 3 columns (e.g. D15C D15C.1 D15C.2). The first 4 letters of the colnames ("D15C") are group names. I need to average the columns…
user1444754
  • 137
  • 1
  • 3
  • 10
10
votes
2 answers

Finding mean and standard deviation across image channels PyTorch

Say I have a batch of images in the form of tensors with dimensions (B x C x W x H) where B is the batch size, C is the number of channels in the image, and W and H are the width and height of the image respectively. I'm looking to use the…
ch1maera
  • 1,369
  • 5
  • 20
  • 42
10
votes
4 answers

CoreMongooseArray to Normal Array

I'm shortlisting the 2 elements from one schema and want to update in another schema. for that i used slice method to shortlist first 2 elements from an array. but am Getting CoreMongooseArray ['element1','element2'] instead of ["element1",…
vinaykumar0459
  • 497
  • 1
  • 6
  • 19
10
votes
2 answers

weighted mean in dplyr for multiple columns

I'm trying to calculate the weighted mean for multiple columns using dplyr. at the moment I'm stuck with summarize_each which to me seems to be part of the solution. here's some example code: library(dplyr) f2a <- c(1,0,0,1) f2b <- c(0,0,0,1) f2c <-…
Jan
  • 3,825
  • 3
  • 31
  • 51