average

How to group by, calculate sum and get average in JavaScript array?

和自甴很熟 提交于 2020-08-20 10:38:18
问题 I have array of object const users = [ { group: 'editor', name: 'Adam', age: 23 }, { group: 'admin', name: 'John', age: 28 }, { group: 'editor', name: 'William', age: 34 }, { group: 'admin', name: 'Oliver', age: 28' } ]; Expected result: //sum sumAge = { editor: 57, // 23+34 admin: 56 // 28+28 } //average avgAge = { editor: 28.5, // (23+34) / 2 admin: 28 //(28+28)/2 } I use reduce() method to group the objects in an array by 'group' and calulate sum: let sumAge = users.reduce((group, age) =>

SQL: Count values higher than average for a group

不羁岁月 提交于 2020-08-05 03:15:23
问题 How can one use SQL to count values higher than a group average? For example: I have table A with: q t 1 5 1 6 1 2 1 8 2 6 2 4 2 3 2 1 The average for group 1 is 5.25. There are two values higher than 5.25 in the group, 8 and 6; so the count of values that are higher than average for the group is 2. The average for group 2 is 3.5. There are two values higher than 3.5 in the group, 5 and 6; so the count of values that are higher than average for the group is 2. 回答1: Try this : select count (*)

Average of multiple files having different row sizes

*爱你&永不变心* 提交于 2020-07-10 03:11:27
问题 I have few files with different row sizes, but number of columns in each file is same. e.g. ifile1.txt 1 1001 ? ? 2 1002 ? ? 3 1003 ? ? 4 1004 ? ? 5 1005 ? 0 6 1006 ? 1 7 1007 ? 3 8 1008 5 4 9 1009 3 11 10 1010 2 9 ifile2.txt 1 2001 ? ? 2 2002 ? ? 3 2003 ? ? 4 2004 ? ? 5 2005 ? 0 6 2006 6 12 7 2007 6 5 8 2008 9 10 9 2009 3 12 10 2010 5 7 11 2011 2 ? 12 2012 9 ? ifile3.txt 1 3001 ? ? 2 3002 ? 6 3 3003 ? ? 4 3004 ? ? 5 3005 ? 0 6 3006 1 25 7 3007 2 3 8 3008 ? ? In each file 1st column

How to calculate the average value of following n rows based on another column - SQL (Oracle) - updated version of previously answered question

夙愿已清 提交于 2020-07-10 01:52:31
问题 I am trying to calculate average monthly value of PREMIUM for each POLICY_ID in monthly basis as shown below screenshot. When a customer updates his/her yearly PAYMENT_FREQUENCY to a value different than 12, I need to manually calculate the average monthly value for the PREMIUM. In addition, average monthly PREMIUM amount can be changed in time. For instance, for the POLICY_ID = 1, starting from "2015/11/01" average monthly premium increased from 120 to 240. How can I achieve the values shown

How to Calculate Average Scroll Depth?

半城伤御伤魂 提交于 2020-06-29 04:24:09
问题 I am trying to calculate the average scroll depth of a page on a website. In Google Analytics, I have events that fire at milestones of 10% increments—so when a user reaches 10% down the page, 20%, 30%, and so on. I have have a custom metrics for each milestone (so I can track via the metrics or via the events). My question is: with this information, how to I calculate the average scroll depth of the page ? Or in other words, how do I find the average distance a user will scroll down the page