You have your averages code a little mixed up. Create your averages list first, then append each average you compute to that: averages=[] for name, v in d.items(): average = (sum(v)/len(v)) averages.append((name, average)) This produces a list of (name, average) tuples that you can then sort: for name, average in...

google-spreadsheet,average,lookup,gs-vlookup

I think I misunderstood. Try this in cell B2. =iferror(average(filter('Sentiment per URL'!$H$2:$H, ('Sentiment per URL'!$D$2:$D=$A2)*('Sentiment per URL'!$F$2:$F=B$1)))) then drag this formula to the right and down as far as needed. See if that works ?...

To apply a filter to an aggregate formula you use the HAVING keyword: SELECT SUM(SaleAmount) AS SaleAmount, CompanyName FROM [Sales Totals by Amount] GROUP BY CompanyName HAVING sum(SaleAmount) > ( Select AVG(SaleAmount) as SaleAmount FROM [Sales Totals by Amount] ) ...

sql-server,dataset,pivot,average

Just sum all the columns and divide it by number of columns you want to sum. Something like this. ;with cte as ( select * from result ) SELECT isnull(Day,'Avg'), Avg([2000]) [2000], Avg([2001]) [2001], Avg([2002]) [2002], Avg([2003]) [2003], Avg([2011]) [2011], ( Avg([2000]) + Avg([2001]) + Avg([2002]) + Avg([2003]) + Avg([2011])...

var idx=1; //change this value if you have several plots. var data = g2.rawData_; var sum = data.map(function(e){return e[idx]}) .reduce(function(a,b){return a+b}); var average = sum/data.length; If you want to keep only values displayed if the graph is zoomed : var idx=1; //change this value if you have several plots. var...

Remove else part from case statement so the values less than 1 will be NULL. Null values will be eliminated by the Avg aggregate. So you will get the average of values which are greater then 0. Try this. Select Avg(Case when [Column]>0 then [Column] end) as [Avg] DEMO Without...

arrays,node.js,average,stocks,moving-average

The ema function returns a vector of the EMA of the previous N points. In your code, N is 10, and since your input vector test has 11 elements, it's possible to calculate 2 moving averages. You can think of a moving average as a "window" of size N (10,...

javascript,elasticsearch,average,datahistory

Just realized that I could do a nested aggregation and then calculate the average of a field inside a aggregation. Here is what I did and it's working properly now: query = { "query": { "bool": { "must": [ { "term": {"deviceId":device} }, { "match": {"eventType":"Connected"} } ], "must_not":[{ "query_string":...

Here's some code that approximates an MCVE (How to create a Minimal, Complete, and Verifiable Example?). Amongst other things, I've compressed the operational/interesting data by leaving one set of zeros before and in between the sets of non-zero data. The calculation for the 3-term weighted average seems to be wrong...

python,arrays,algorithm,average

data = [1,2,3,5,11,12,13,15,22,25,27,30] # divide it into blocks like [[a .. a+10], [b .. b+10], ...] result = [] block = None for d in data: if block: if d <= hi: # belongs to current block block.append(d) else: # start a new block result.append(block) # finish previous block block...

I think the problem is in the do while loop where you fill the Map with data to be averaged later. At the end of the loop you add the array weights to the map. But in fact this is the same array on every iteration. So every iteration will...

The function you're looking for is averageif. If your two columns are A and B, and you have 10 rows: =AVERAGEIF(A1:A10,"Set 1",B1:B10) =AVERAGEIF(A1:A10,"Set 2",B1:B10) =AVERAGEIF(A1:A10,"Set 3",B1:B10) ...

I tested your code in EMU8086, and this is the solution that worked for me, next is your data segment with 5 little changes : data segment sum dw 0 ;<========================== dw 0 ;<========================== num dw 0 ;<========================== dw 0 ;<========================== msg1 db 'Enter 20 numbers:', '$' msg2 db 0dh,0ah,'Average:...

Just use a pivot table: Select all the data (including headers) in columns Latitude, Longitude, and Data. Choose Insert > PivotTable. Drag Latitude and Longitude into the Row Labels section. Choose PivotTable Tools > Design > Report Layout > Show in Tabular Form and Repeat All Item Levels. Also choose...

May be this helps library(dplyr) library(tidyr) add_rownames(df1) %>% gather(Var, Val, -x, -rowname) %>% extract(Var, into='Var', '([^0-9]*).*') %>% group_by(rowname, x, Var) %>% summarise(Mean=mean(Val), Min=min(Val), Max=max(Val)) Or using base R res <- do.call(rbind, lapply(split(names(df1)[-1], sub('\\d+$', '', names(df1)[-1])), function(x) { x1 <- df1[x] data.frame(x=df1[1],Mean=rowMeans(x1), Max=do.call(pmax, x1), Min=do.call(pmin, x1))})) data df1 <- structure(list(x =...

Here is a couple of approaches: -With base R: aggregate(length~name,d,mean) # name length # 1 a 5.0 # 2 b 8.5 # 3 c 7.0 -With the dplyr package (definitely worth spending time to explore) library(dplyr) d %>% group_by(name) %>% summarize(avg=mean(length)) # Source: local data frame [3 x 2] #...

Here's how I would do it Use lubridate to create a month variable to group by in dplyr and then get means. library(lubridate) library(dplyr) df %>% group_by(month = month(df$V1)) %>% summarize(mean = mean(velocity)) month mean 1 4 95.36530 2 5 95.53038 3 6 95.35810 4 7 95.24634 5 8 95.81465...

Use slicing of the vector: mean = np.mean(y_avg[5:15]) If you want a mid point, this works for even sized windows: def mean_slice(midp, size, array): slice_index = [midp - (size/2), midp + (size/2)] # Remove out of bounds indexes slice_index = [i if i > 0 else 0 for i in...

select avg(value2),KEY from testavg GROUP BY key order by key; 8.66666666666666666666666666666666666667 10 20 12 EDIT: Specs are still not clear but this might be what you need... with gr1 as (select key,sum(value2) sumvalue from testavg group by key) , gr2 as (select key,value,sum(value2) sumvalue from testavg GROUP BY key,value)...

Try data.table library(data.table) setDT(shop)[, lapply(.SD, mean), shop_id] # shop_id Assets Liabilities sale profit #1: Shop A 8.0 5.333333 8.666667 2.333333 #2: Shop B 5.0 9.000000 15.000000 6.000000 #3: Shop C 5.5 10.000000 14.000000 7.000000 Or library(dplyr) shop %>% group_by(shop_id)%>% summarise_each(funs(mean)) # shop_id Assets Liabilities sale profit #1 Shop A 8.0...

you can write like outer query and your query as inner query .. SELECT Sum(Ontime) AS Ontime ,AVG(actual) AS Actual ,Sum(task_count) AS task_count FROM ( SELECT AVG(CASE WHEN a.ontime = 'on time' THEN 100 ELSE 0 END) * COUNT(a.country) AS ontime ,AVG(CASE WHEN a.accuracy = 'accurate' THEN 100 ELSE 0...

Averaging the columns is trivial, and you can retain most of the original formatting using printf: $ awk 'NR==1 { printf "%s %8s\n", $0,"NEWAVG"} NR>1 { printf "%s %7.2f\n", $0,($11+$12+$13)/3 }' /tmp/data VALID_TIME STN CDF05 CDF10 CDF20 CDF30 CDF40 CDF50 CDF60 CDF70 CDF80 CDF90 CDF95 MEAN SD NEWAVG 2015031018 KMGM...

So, before I begin: I'd strongly recommend that you teach yourself how to use the Javascript interface to Apple Events, rather than the Applescript language itself. Applescript is a really weird language, and its quirks are largely unique; learning it is going to be frustrating, and won't help you learn...

python,sorting,dictionary,average

You can make your dictionary have the following structure: diction1 = {'zor': [10, 21,], 'bob': [30]} Then create a new dictionary where you store the name, and the average score: averages_dct = {'zor': 15.5, } Your code should look something like this: diction1 = {'john': [10, 20], 'mary': [12,], 'chris':...

Just map your [{x1,y1}, {x2,y2}, ... {xN,yN}] pairs to a [y1, y2, ... yN] series, which is what that moving average function expects: movingAverageLine(data.map(function(d) { return d.y; })) ...

With the aggregation framework, you would need to first apply the $unwind operator on the ratings array field first as your initial aggregation pipeline step. This will deconstruct the ratings array field from the input documents to output a document for each element. Each output document replaces the array with...

First a caveat: like you I am new to mongoDB so although the answer given below appears to work, there may well be a more concise / performant way to acheive the same result. Here is the sample dataset I constructed: /* 0 */ { "_id" : ObjectId("54d62ce0e11e084bc1366195"), "kick_off_date" :...

data = [ # some made-up numbers for illustration ("France", 2006, 64026, 72527, 87442, 98435), ("France", 2007, 82051, 75285, 97193, 69527), ("France", 2008, 88827, 51960, 77807, 81725), ("Germany", 2006, 85653, 83989, 66603, 66559), ("Germany", 2007, 85431, 83590, 88482, 87827), ("Germany", 2008, 67184, 96350, 84947, 67874), ("Greece", 2006, 72062, 55844, 51758,...

I need to select all graphics software (category) that runs on linux (platform) and I need the minimum, maximum, and average price (version/@price). If, as I suspect, you are using XSLT 1.0, with no support for EXSLT extension functions, try something along the lines of: XSLT 1.0 <xsl:stylesheet version="1.0"...

sql-server,if-statement,sum,case,average

This does the trick!: --SET UP Table1 CREATE TABLE Table1 (ID INT, final INT, [Date] DATETIME) INSERT Table1 VALUES (1, 236, '20141102') INSERT Table1 VALUES (2, 10, '20120107') INSERT Table1 VALUES (3, 58, '20100209') --SET UP Table2 CREATE TABLE Table2 (ID INT, final INT, [Date] DATETIME) INSERT Table2 VALUES (1,...

You can fetch all items and prices data and match them up with WHERE, then use GROUP BY to collect duplicates as one row. With COUNT(..) you can get the row count for each item. This should do the trick: SELECT COUNT(items.itemid) as cnt, items.itemid, prices.priceid FROM items, prices WHERE...

Use a derived table: select avg(dt.vix) from (select vix from my_table order by date desc limit 3) dt ...

To answer your comment, this works for me: clear set more off input /// mnbr firm cont 1591 2 1 9246 6 . 812 6 1 674 6 1 end list // problem 1 inspect firm display r(N_unique) // problem 2 bysort firm: egen totc = total(cont) by firm: gen...

You may pass average number via command line using 2 args: current average value and the number of iterations performed. Then: NewAverage = ((CurrentAverage*N) + CurrentValue) / (N+1); where N is the number of iterations.

arrays,assembly,floating-point,average,nasm

Glad you found a solution! Could you tell us why you did the following the hard way? .setavg: ;average array set up (used to output) mov [avg+ebx], eax push eax mov eax, ebx add eax, 4 mov ebx, eax pop eax add eax, 1 loop .setavg Usual version .setavg: ;average...

you can achieve this via PROC SQL Select count(*)/count(distinct rid) from patients; ...

python,python-3.x,dictionary,average

Okay, so let's iterate over all dictionary keys and average the items: avgDict = {} for k,v in StudentGrades.iteritems(): # v is the list of grades for student k avgDict[k] = sum(v)/ float(len(v)) now you can just see : avgDict Out[5]: {'Ivan': 3.106666666666667, 'Martin': 4.816666666666666, 'Stoyan': 3.89, 'Vladimir': 5.433333333333334} From...

sql,sql-server,max,average,min

Remove b,c from group by and add period instead SELECT name,period, max(b), max(c), min(b), min(c) FROM tablename group by name,period ...

An alternative solution: select MRr, count(*) as _count from mnr group by MRr having count(*) > (select count(*) / count(distinct mrr) * 1.0 from mnr) ...

You have a missing FILLER PIC X after the Zip. You need to go through with the actual data and make sure that all the fields line up with your definitions. Don't rely on the written definitions you included. The data is what it really is. Now that comments aren't...

The best way to do this would be to use window functions: SELECT OrganizationCode, CreatedDate , AVG(TotalCost) OVER ( PARTITION BY CreatedDate ) AS [Daily Average] , COUNT(*) OVER ( PARTITION BY CreatedDate ) AS [Daily Amount] FROM #TempLocalOrg; The above assumes that dates are rounded or truncated to the...

file is a list of strings. The sum function expects a number. To get an average you should convert each entry in file to a number: e.g. file = [float(x) for x in file]...

sql,ms-access-2007,max,average

The problem is that the maximum of prod and the maximum of area are rarely in the same row. You should also learn to use explicit join syntax. A simple rule: never use a comma in the from clause. This may be what you want: SELECT temp.hhid, temp.country, temp.max_prod, temp.max_area,...

java,arrays,list,netbeans,average

If you want to find the average stored in an array , try the following function. public static double average(int[] marks) { int sum = 0; double average; for(int element: marks) { sum = sum + element; } average = (double)sum / marks.length; return average; } Hope it helps !...

sql,aggregate,average,orient-db

EDITED create class Puntua extends E create class Sitio extends V create class Persona extends V create vertex Persona set name = 'person' # returns #17:0 create vertex Sitio set place = 'mcdonals' # returns #16:0 create vertex Sitio set place = 'burgerking' create vertex Sitio set place = 'glicinia'...

SQL Server only does integer division on intgers, so you should convert your values to non-integer numbers. I often do this using * 1.0, something like: (CASE WHEN SUM(z.[SumTarget$]) <> 0 THEN (1-(SUM(z.[SumBackorder])+SUM(z.[SumStockedOut]))/SUM(1.0 * z.[CountofNo])) END) as [SumAvPerc] ...

sorting,assembly,average,procedure,8086

The problem lies with these two lines (and possibly similar elsewhere): mov array[bp], ax mov array[bp+2], dx By default, the bp register addresses the stack segment, not the data segment where array is. You must either use another index register, or over ride the segment with mov ds:array[bp], ax mov...

r,time-series,average,mean,moving-average

For returning the last value try: values$last = c(NA,values[-nrow(values),1]) or the lag function could be used as well I believe....

So what I'd do is creating an intermediate dictionary with the averages of your users and then show that sorted. You might want to take a look to what operator.itemgetter and sorted do. import operator dictionary = { 'Louie Scored': [3, 5, 2], 'Thomas Scored': [8, 4] } averages =...

A fast way to do it: >>> s = pd.Series(range(10)) >>> s 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 >>> ((s + s.shift(-1)) / 2)[::2] 0 0.5 2 2.5 4 4.5 6 6.5 8 8.5 The "proper...

I think you can filter the list first and then get the average: MeasuredValues _ .Where(Function(measure) cDate(measure.Key) >= dateFrom And cDate(measure.Key) <= dateTo) _ .Average(Function(measure) measure.Value) REGARDING UPDATE 2: If I understand the new issue corrently, you're getting an error on the Average if Where returns no elements. I know...

If you have a matrix you need to sum the elements of the nested lists. You also need to convert those to integers: total = sum(int(i) for sublist in outerlist for i in sublist) length = sum(len(sublist) for sublist in outerlist) average = total / length This assumes you wanted...

You can calculate the sum weight of non-zero values while iterating over them, and do the division by the sum weight at the end: vs := []int{500, 400, 0, 300} ws := []float64{0.1, 0.2, 0.3, 0.4} sumWeight, avg := 0.0, 0.0 for i, v := range vs { if v...

Not clear where Rejection_Rate is located in your tables. Compare with this... CREATE TABLE Nums ( ProjName VARCHAR(20), ProjVal DOUBLE ); INSERT INTO Nums VALUES ("A", 100), ("A", 175), ("B", 200), ("B", 100); SELECT DISTINCT ProjName, Round(Avg(ProjVal),2) Average FROM Nums GROUP BY ProjName; Results were 137.5 for project "A" and...

First get rid of semi-colon after while while (cin >> input); ~~ Second you math is wrong third argument to std::accumulate is initial value of sum Instead do: float average = accumulate( v.begin(), v.end(), 0.0)/v.size(); Also, element of container data type should match the container type i.e. float use float...

java,while-loop,average,do-while

It doesn't work because your loops are separated, so if first is false, second works only once and then stops. Try something like this: import java.util.Scanner; public class Average { public static void main(String[] args){ Scanner scanner = new Scanner(System.in); System.out.println("The program will calculate the average of the user inputted...

I guess something like this would work: //calc averages for (Entry<Integer, double[]> entry : cached_weights.entrySet()) { int key = entry.getKey(); double[] value = entry.getValue(); AVERAGED_WEIGHTS[ key - 1 ] += value[ key - 1 ]; } But then, must make some term for dividing by the # of iterations at...

ms-access,average,ms-access-2013

To get the average for each fieldname, just do this in a query: SELECT FieldName, Avg(FieldNum) as AvgQty FROM MyTable GROUP BY FieldName ORDER BY FieldName This will also sort the fieldname column for you. EDIT: I think you can do what you asked for in your comment, but you...

I would use awk like this: awk 'NR==1 {print $0, "Avg.temp", "Hum"; next} {$(NF+1)=($2+$3)/2; $(NF+1)=$5*$6}1' file or: awk 'NR==1 {print $0, "Avg.temp", "Hum"; next} {print $0, ($2+$3)/2, $5*$6}' file This consists in doing the calculations and appending them to the original values. Let's see it in action, piping to column...

The accepted answer to Using awk to bin values in a list of numbers is: awk '{sum+=$1} NR%3==0 {print sum/3; sum=0}' inFile The obvious extension to average all the columns is: awk 'BEGIN { N = 3 } { for (i = 1; i <= NF; i++) sum[i] += $i...

r,for-loop,matrix,average,moving-average

this should get you started (even though I would convert the matrices to data.frames): #some sample data m <- matrix(sample(10000, 365*4),365,4) # get the mean of all the columns of your matrix colMeans(m) if you have 3 matrices and you want to combine the results I would do: # some...

python,python-2.7,python-3.x,install,average

Did I install "Pycharm" wrong? NO in python 3 input returns a string a = int(input("please enter a:")) #this will make the input an integer # warning if the user enters invalid input it will raise an error should work fine you should also change your print line to print('...

I think this is what you were trying to do public static void main(String[] args) { Scanner keyboard=new Scanner(System.in); System.out.println("Enter file name to be written"); String file=keyboard.next(); File fileName=new File(file); try{ FileOutputStream fo=new FileOutputStream(fileName); ObjectOutputStream output=new ObjectOutputStream(fo); System.out.println("Enter numbers"); System.out.println("enter q to quit"); String number; do { number=keyboard.next(); if(number.equals("q")){ output.writeUTF(number);...

python,list,csv,python-3.x,average

When you call a_list.append(row[0:8]) you're appending an array using only indexes 0, 1, 2, 3, 4, 5, 6, and 7 from row. This means that when you later iterate a_list, the x variable only has indexes up to 7, and you're trying to access 8. Quick example: >>> row =...

Instead of using that array formula. There is a formula that does this for you called AVERAGEIFS. Which can take in multiple criteria to determine what to average. We can add as many criteria as needed to determine our final results. To test if the date is within the year...

excel,average,conditional-statements

An AVERAGEIFS function should take care of this easily providing your version of Excel is 2007 or newer. AVERAGEIFS(<average_range>, <criteria_range1>, <criteria1>, <criteria_range2>, <criteria2>…) The size of the ranges used for <average_range> and one or more -<criteria_rangeX>- have to be the same but they do not have to be the same...

Being impatient, I think this is what you are looking for. You didn't specify which SQL Server version you're using although. DECLARE @topParam INT = 3; -- Default DECLARE @student TABLE (StudentID INT); -- Just for testing purpose DECLARE @examines TABLE (StudentID INT, Grades INT); INSERT INTO @student (StudentID) VALUES...

sql,sql-server,average,dimensional-modeling

If I understand well your needs, you want to know the average number of product sold between 2012 and 2014 included, which is the number of product sold divided by 36. In order to manage products which have not been sold during this period, the key is to do a...

import java.util.Scanner; public class ArrAvg { public static void main(String[] args) { int a[] = {1,2,3,4,5,6,7,8,9,10}; int occur = 0; double sum = 0; double avg = 0; for (int i = 0; i < a.length; i++) { if (a[i] == 4) { occur++; } } for (int i =...

Your query is basically fine. Your date constant is not. Dates constants should be enclosed in single quotes: SELECT AVG(PAM_1) FROM MyTable WHERE DATE = '2015-01-01'; If the date could have a time component, then the following is the best way to handle this: SELECT AVG(PAM_1) FROM MyTable WHERE DATE...

Here's a vectorized solution: m <- matrix(1:96,8); m; ## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] ## [1,] 1 9 17 25 33 41 49 57 65 73 81 89 ## [2,] 2 10 18 26 34 42 50 58 66 74 82 90 ##...

excel,vba,excel-vba,excel-formula,average

As for formula solution, if the cell containing "OUTPUT" was C3, the following formula should be put in D4 and pasted downwards. =IF(C4="","",IF(C5<>"","",IF(C3="",C4,AVERAGE(C2:C4)))) This will only work if your top 3 values are at the bottom of every group (model)....

sql,sql-server,inner-join,average

Try something like this: Select a.StudentName, TableAvg.class, a.score From TableA a inner Join (select class, avg(score) as AvgScore From TableA group by class) TableAvg On a.score > TableAvg.AvgScore and a.class = TableAvg.class Untested code......

You can use zip within a list comprehension: >>> from __future__ import division >>> [[set(i).pop(),round(sum(j)/len(j),0)] for i,j in [zip(*i) for i in data]] [['apple', 2.0], ['cake', 7.0], ['chocolate', 7.0], ['grapes', 6.0]] The zip function here would separate your values from names in nested lists: >>> [zip(*i) for i in data]...

You need to initialize total to zero: int total = 0; It is currently uninitialised and could be anything. A couple of other things to watch out for: Your median calculation relies on the vector being sorted If there is an even number of values the median is usually defined...

As per Tolerant average (ignore #NA, etc.) (which is even more demanding than the present case), =AVERAGE(IF(YEAR(A:A)=2012,N:N)) with Ctrl+Shift+Enter works (tested)....

well if the output is the same every time you could do a few things. You could remove the first bit of information "rtt min/avg/max/mdev = " by doing the following. >>> yourString[23:] where 23 is the number of characters you want to cut off the front. Then do the...

python,arrays,sorting,replace,average

You could use Raymond Hettinger's cluster function: from __future__ import division def cluster(data, maxgap): """Arrange data into groups where successive elements differ by no more than *maxgap* >>> cluster([1, 6, 9, 100, 102, 105, 109, 134, 139], maxgap=10) [[1, 6, 9], [100, 102, 105, 109], [134, 139]] >>> cluster([1, 6,...

I am bored, and a little buzzed, so I thought I would just throw out some working code that you might be able to learn from: # A Student object will just take care of tracking the name and speed. # Classes like this in Python (with no methods) are...

algorithm,math,average,moving-average

Your solution is essentially the "standard" optimal online solution for keeping a running track of average without storing big sums and also while running "online", i.e. you can just process one number at a time without going back to other numbers, and you only use a constant amount of extra...

postgresql,aggregate,average,derived

You are naming the ProductAverages, so your table aliases should reference it, not c - which can be used only in the inner query: SELECT name, -- Here AVG(avgvalue) FROM ( SELECT c.name, p.name, AVG(a."value") AS avgvalue FROM answers a INNER JOIN survey_responses sr ON sr.id = a.survey_response_id AND a.question_id...

Just keep track of the highest average in another variable. Then in your score == -1 condition check to see if the current average is higher than the highest average, and if so make current the new highest. Then after your for loop you could print out the highest average.

You can use JavaScript's arguments inside a function to handle arbitrary number of parameters. var Calculator = { average: function() { var num = 0,length=arguments.length; if(!length) return 0; for (var i = 0; i < length; i++) num = num + arguments[i]; var divide = num/length; return divide; } };...

java,loops,methods,average,standard-deviation

Try: long sum = 0; long sumSquare = 0; for(int c = 0 ; c < 10 ; c++) { long start = System.nanoTime(); // do work long end = System.nanoTime(); sum += end - start; sumSquare += Math.pow(end - start, 2); } double average = (sum * 1D) /...

python,list,dictionary,average

Just divide the sum of values by the length of the list: print sum(d['value'] for d in total) / len(total) Note that division of integers returns the integer value. This means that average of the [5, 5, 0, 0] will be 2 instead of 2.5. If you need more precise...

SELECT `date`, `output`, (SELECT avg(`output`) from Table1 where Table1.`date` <= b.`date`) as `average` FROM Table1 b sqlfiddle here...

python,file,sorting,text-files,average

EDIT: Updated the answer, after understanding what user was trying to do. The first issue I have with this code is that it is very redundant. Python follows DRY (Do not Repeat Yourself) approach. Take the redundant code and create a function out of it and call the function multiple...

You haven't explicitly asked a question so I'll try and comply to the "set me in the right direction" part. I'd suggest re-formatting the loop structure to a cleaner one, like this: double total; for(int student = 1; student <= 4; student++) { System.out.printf("Student %d\n", student); double sum = 0,...

You almost had it, all you have to do is place your TOP 30 inside sub-query or CTE and than do your AVG SELECT AVG(Total_MB - ( East_MB + West_MB )) AS Other ,AVG(East_MB) AS East ,AVG(West_MB) AS West FROM ( SELECT TOP 30 * FROM [dbo].[stats] WHERE Rack_Code =...

Even though it's kind of strange, what you are trying to do, and I'm sure there is a better way of doing it, here's how you can do it: float onTheFlyAverage() { static int nCount=0; float avg, newAvg; int newNumber = getRandomNum(); nCount++; //increment the total number count avg =...

First calculate the days between each date (I'm assuming SQL Server): select [dtmDateSetup], [dtmWelcomeLetterSent], DATEDIFF(day,dtmDateSetup,dtmWelcomeLetterSent) from [tblCustomer] where [intSalesPersonID] = 1 AND [dtmWelcomeLetterSent] IS NOT NULL Then the average is easy: select AVG(DATEDIFF(day,dtmDateSetup,dtmWelcomeLetterSent)) from [tblCustomer] where [intSalesPersonID] = 1 AND [dtmWelcomeLetterSent] IS NOT NULL ...

I don't think your code does what you think it does. No matter whether you number is odd or even, you are always adding to the sum. So in fact your current code is currently dividing sum/oddCount which the sum of all numbers divided by the number (count) of odd...

r,ggplot2,average,bar-chart,multiple-columns

This is a basic aggregation question, so the typical starting point should be aggregate: > aggregate(avgct ~ gregion + lregion, mydf, mean) gregion lregion avgct 1 1 e 1.0465 2 2 e 0.9080 3 3 e 1.1670 4 1 t 1.2250 5 2 t 1.7470 6 3 t 0.6790 There...

To find the number of days in a month you can use the days_in_month function in the lubridate package. The argument takes a datetime object so you have to convert your Date column to a known date/datetime-based class (i.e. "POSIXct, POSIXlt, Date, chron, yearmon, yearqtr, zoo, zooreg, timeDate, xts, its,...