average

Get average based on value in another row

不羁岁月 提交于 2019-12-01 00:45:46
I have values in an Excel file like this: QR | QR AVG | val1 | q1 5 q1 3 q1 4 q2 7 q2 9 q3 10 q3 11 q3 12 q3 11 q4 5 q5 5 q5 7 And I would like the QR AVG field to represent the average value partitioned by different QR values. In other words, I'd like to have the following values after my calculation: QR | QR AVG | val1 | q1 4 5 q1 4 3 q1 4 4 q2 8 7 q2 8 9 q3 11 10 q3 11 11 q3 11 12 q3 11 11 q4 5 5 q5 6 5 q5 6 7 Where I don't know the exact number of rows that I will have, and I will be intermittently adding rows randomly into the table. I would prefer not to write a macro to do this if

R running average for non-time data

≯℡__Kan透↙ 提交于 2019-12-01 00:37:30
This is the plot I'm having now. It's generated from this code: ggplot(data1, aes(x=POS,y=DIFF,colour=GT)) + geom_point() + facet_grid(~ CHROM,scales="free_x",space="free_x") + theme(strip.text.x = element_text(size=40), strip.background = element_rect(color='lightblue',fill='lightblue'), legend.position="top", legend.title = element_text(size=40,colour="lightblue"), legend.text = element_text(size=40), legend.key.size = unit(2.5, "cm")) + guides(fill = guide_legend(title.position="top", title = "Legend:GT='REF'+'ALT'"), shape = guide_legend(override.aes=list(size=10))) + scale_y_log10(breaks

average of a number of arrays with numpy without considering zero values

天大地大妈咪最大 提交于 2019-12-01 00:36:58
I am working on numpy and I have a number of arrays with the same size and shape like: a= [153 186 0 258] b=[156 136 156 0] c=[193 150 950 757] I want to have average of the arrays, but I want the program to ignore the zero values in the computation. So, the resulting array for this example will be: d=[167.333 157.333 553 507.5] this is the result of this computation: d=[(153+156+193)/3 (186+136+150)/3 (156+950)/2 (258+757)/2] . Is it possible to do that? >>> import numpy as np >>> a = np.array([153, 186, 0, 258]) >>> b = np.array([156, 136, 156, 0]) >>> c = np.array([193, 150, 950, 757]) >>>

R: What are the best functions to deal with concatenating and averaging values in a data.frame?

走远了吗. 提交于 2019-11-30 23:33:10
I have a data.frame from this code: my_df = data.frame("read_time" = c("2010-02-15", "2010-02-15", "2010-02-16", "2010-02-16", "2010-02-16", "2010-02-17"), "OD" = c(0.1, 0.2, 0.1, 0.2, 0.4, 0.5) ) which produces this: > my_df read_time OD 1 2010-02-15 0.1 2 2010-02-15 0.2 3 2010-02-16 0.1 4 2010-02-16 0.2 5 2010-02-16 0.4 6 2010-02-17 0.5 I want to average the OD column over each distinct read_time (notice some are replicated others are not) and I also would like to calculate the standard deviation, producing a table like this: > my_df read_time OD stdev 1 2010-02-15 0.15 0.05 5 2010-02-16 0.3

Query to calculate average time between successive events

与世无争的帅哥 提交于 2019-11-30 21:16:13
My question is about how to write an SQL query to calculate the average time between successive events. I have a small table: event Name | Time stage 1 | 10:01 stage 2 | 10:03 stage 3 | 10:06 stage 1 | 10:10 stage 2 | 10:15 stage 3 | 10:21 stage 1 | 10:22 stage 2 | 10:23 stage 3 | 10:29 I want to build a query that get as an answer the average of the times between stage(i) and stage(i+1). For example, the average time between stage 2 and stage 3 is 5: (3+6+6)/3 = 5 Vilx- Aaaaand with a sprinkle of black magic: select a.eventName, b.eventName, AVG(DATEDIFF(MINUTE, a.[Time], b.[Time])) as

Replace NA with average of the case before and after the NA

心不动则不痛 提交于 2019-11-30 20:37:37
问题 Say I have the following data.frame: t<-c(1,1,2,4,5,4) u<-c(1,3,4,5,4,2) v<-c(2,3,4,5,NA,2) w<-c(NA,3,4,5,2,3) x<-c(2,3,4,5,6,NA) df<-data.frame(t,u,v,w,x) I would like to replace the NAs with values that represent the average of the case before and after the NA, unless a row starts (row 4) or ends (row 5) with an NA. When the row begins with NA, I would like to substitute the NA with the following case. When the row ends with NA, I would like to substitute the NA with the previous case. Thus

R running average for non-time data

荒凉一梦 提交于 2019-11-30 19:39:37
问题 This is the plot I'm having now. It's generated from this code: ggplot(data1, aes(x=POS,y=DIFF,colour=GT)) + geom_point() + facet_grid(~ CHROM,scales="free_x",space="free_x") + theme(strip.text.x = element_text(size=40), strip.background = element_rect(color='lightblue',fill='lightblue'), legend.position="top", legend.title = element_text(size=40,colour="lightblue"), legend.text = element_text(size=40), legend.key.size = unit(2.5, "cm")) + guides(fill = guide_legend(title.position="top",

Is there any pythonic way to find average of specific tuple elements in array?

∥☆過路亽.° 提交于 2019-11-30 16:26:33
问题 I want to write this code as pythonic. My real array much bigger than this example. ( 5+10+20+3+2 ) / 5 print(np.mean(array,key=lambda x:x[1])) TypeError: mean() got an unexpected keyword argument 'key' array = [('a', 5) , ('b', 10), ('c', 20), ('d', 3), ('e', 2)] sum = 0 for i in range(len(array)): sum = sum + array[i][1] average = sum / len(array) print(average) import numpy as np print(np.mean(array,key=lambda x:x[1])) How can avoid this? I want to use second example. I'm using Python 3.7

Average stock history table

☆樱花仙子☆ 提交于 2019-11-30 16:23:16
I have a table that tracks changes in stocks through time for some stores and products. The value is the absolute stock, but we only insert a new row when a change in stock occurs. This design was to keep the table small, because it is expected to grow rapidly. This is an example schema and some test data: CREATE TABLE stocks ( id serial NOT NULL, store_id integer NOT NULL, product_id integer NOT NULL, date date NOT NULL, value integer NOT NULL, CONSTRAINT stocks_pkey PRIMARY KEY (id), CONSTRAINT stocks_store_id_product_id_date_key UNIQUE (store_id, product_id, date) ); insert into stocks

Python 3.4 - How to get the average of dictionary values? [closed]

蹲街弑〆低调 提交于 2019-11-30 16:21:40
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 4 years ago . I have the following dictionary: StudentGrades = { 'Ivan': [4.32, 3, 2], 'Martin': [3.45, 5, 6], 'Stoyan': [2, 5.67, 4], 'Vladimir': [5.63, 4.67, 6] } I want to make a function that prints the average of the grades of the students, i.e. the average of the values, but I have no