average

How to find mode across variables/vectors within a data row in R

[亡魂溺海] 提交于 2019-12-02 01:03:31
问题 This question was migrated from Cross Validated because it can be answered on Stack Overflow. Migrated 6 years ago . Does anyone know how to find the mode (most frequent across variables for a single case in R? For example, if I had data on favorite type of fruit (x), asked nine times (x1-x9) for each respondent (id) in a survey. If I wanted to find the modal response for each test subject in the first five times asked, how would I program that in R? More succinctly, with the example data is

Calculating Average from a CSV File

痞子三分冷 提交于 2019-12-02 00:31:46
I have a CSV file, format as follows: City,Job,Salary Delhi,Doctors,500 Delhi,Lawyers,400 Delhi,Plumbers,100 London,Doctors,800 London,Lawyers,700 London,Plumbers,300 Tokyo,Doctors,900 Tokyo,Lawyers,800 Tokyo,Plumbers,400 Lawyers,Doctors,300 Lawyers,Lawyers,400 Lawyers,Plumbers,500 Hong Kong,Doctors,1800 Hong Kong,Lawyers,1100 Hong Kong,Plumbers,1000 Moscow,Doctors,300 Moscow,Lawyers,200 Moscow,Plumbers,100 Berlin,Doctors,800 Berlin,Plumbers,900 Paris,Doctors,900 Paris,Lawyers,800 Paris,Plumbers,500 Paris,Dog catchers,400 I want to find the average of the total salaries. This is my code: `

Multiple averages over evenly spaced intervals

天涯浪子 提交于 2019-12-02 00:27:54
问题 I'm trying to learn SQL so be patient with me. I'm using PostgreSQL 9.3 I want to average a column based on a window of dates. I've been able to write window functions that accomplish this with a set interval but I'd like to be able to be able to do this with a growing interval . By this I mean: average values from date_0 to date_1 average values from date_0 to date_2 average values from date_0 to date_3 ..... so date date_0 stays the same and date_x grows and creates a larger sample I'm

Calculating moving-averages of variable parameters

那年仲夏 提交于 2019-12-01 22:57:50
I have an integer property which is updated every second with a signal-strength value ranging from 0 - 100. I'd like to be able to keep an ongoing measure of the moving average over the last 10, 25, 50 measurements. What's the most efficient way of doing this? I'm currently thinking of implementing a set of FIFO queues using NSMutableArray and popping the leading value every time I add a new one at the end once the array has the requisite number of entries. However, I'm not sure if there's a more efficient way of doing this or not. A queue is the right way. The real efficiency comes with how

c# float [] average loses accuracy

徘徊边缘 提交于 2019-12-01 22:35:59
I am trying to calculate average for an array of floats. I need to use indices because this is inside a binary search so the top and bottom will move. (Big picture we are trying to optimize a half range estimation so we don't have to re-create the array each pass). Anyway I wrote a custom average loop and I'm getting 2 places less accuracy than the c# Average() method float test = input.Average(); int count = (top - bottom) + 1;//number of elements in this iteration int pos = bottom; float average = 0f;//working average while (pos <= top) { average += input[pos]; pos++; } average = average /

Multiple averages over evenly spaced intervals

為{幸葍}努か 提交于 2019-12-01 20:48:54
I'm trying to learn SQL so be patient with me. I'm using PostgreSQL 9.3 I want to average a column based on a window of dates. I've been able to write window functions that accomplish this with a set interval but I'd like to be able to be able to do this with a growing interval . By this I mean: average values from date_0 to date_1 average values from date_0 to date_2 average values from date_0 to date_3 ..... so date date_0 stays the same and date_x grows and creates a larger sample I'm assuming there is a better way than running a query for each range I'd like to average. Any advice is

How to find mode across variables/vectors within a data row in R

天涯浪子 提交于 2019-12-01 20:46:47
Does anyone know how to find the mode (most frequent across variables for a single case in R? For example, if I had data on favorite type of fruit (x), asked nine times (x1-x9) for each respondent (id) in a survey. If I wanted to find the modal response for each test subject in the first five times asked, how would I program that in R? More succinctly, with the example data is below, how do I find the MODE within each case? id x1 x2 x3 x4 x5 MODE(x1-x5)? 1 3 5 6 4 5 5 2 7 4 7 4 7 7 3 3 4 4 4 3 4 4 3 2 2 2 3 2 The modeest package provides implements a number of estimators of the mode for

Linq - calculate multiple averages in one query

点点圈 提交于 2019-12-01 18:24:21
问题 I'm trying to convert some SQL queries into Linq to avoid multiple trips to the database. The old SQL I'm trying to convert does: SELECT AVG(CAST(DATEDIFF(ms, A.CreatedDate, B.CompletedDate) AS decimal(15,4))), AVG(CAST(DATEDIFF(ms, B.CreatedDate, B.CompletedDate) AS decimal(15,4))) FROM dbo.A INNER JOIN dbo.B ON B.ParentId = A.Id So I've created two C# classes: class B { public Guid Id { get; set; } public DateTime CreatedDate { get; set; } public DateTime CompletedDate { get; set; } } class

In Python, how to get the sum and average while in a loop

*爱你&永不变心* 提交于 2019-12-01 14:21:58
I've managed to implement a loop but keep getting a syntax error when I try the sum function. I need the numbers input by the user to be totalled and the average given as well. This has to be outputted to the user. Could you please guide me on where to go from here, thank you. This is what I've done so far: while 1: NumCalc = input ("Enter Number :") if NumCalc == "done": break This is what you can do if you want to compute the sum and the mean after the loop ends: nums = [] while 1: NumCalc = input ("Enter Number:") if NumCalc == "done": break nums.append(float(NumCalc)) print('Sum:', sum

Getting the above average student from database

泪湿孤枕 提交于 2019-12-01 14:03:27
I've created a view that contains: student_full_name subject_code result Jennifer Higgins CS1234 81 Jennifer Higgins CS1235 90 Kal Penn CS1234 70 Kal Penn CS1235 60 Han Solo CS1234 45 Han Solo CS1235 70 I am trying to get: Average result of each student so like say Jennifer Higgins enrolled in CS1234 and CS1235. Her average mark would be 85.50. Then Jennifer Higgins marks would be compared to the average mark of all enrolments So totalling up the AVG(result) for all subjects. The query would then list all the students who are getting above average scores. I know I have to use a sub query here