aggregate

aggregate QUERY - 3 month average per person for every month

我只是一个虾纸丫 提交于 2019-12-11 07:28:15
问题 Suppose I have view of data in bigquery Person | Amount | yearMonth --------------------------- AA | 100 | 201701 AA | 200 | 201702 AA | 300 | 201703 AA | 70 | 201704 AB | 10 | 201701 AB | 50 | 201702 AB | 60 | 201703 AB | 70 | 201704 AC | 70 | 201701 AC | 80 | 201702 AC | 30 | 201703 AC | 10 | 201704 Now, I need to get the average of this for the last 3 months for every person every month Expected Results: Person | Amount | yearMonth --------------------------- AA | 200 | 201703(avg of

MongoDB aggregate project return an array of _id [duplicate]

蹲街弑〆低调 提交于 2019-12-11 07:06:05
问题 This question already has answers here : How to return array of string with mongodb aggregation (2 answers) Closed 2 years ago . As we know if we want to get an array of _id we can do: db.collections.distinct("_id"); My question is how can I get an array of _id if I need to do a complicate logic with aggregate. Ex: db.getCollection('users').aggregate({ $match : { is_register_completed : { $ne : true} } } //other operator like $lookup, $group , { $project : {_id:1} } ) I get { "_id" : "1", "

Class based weighted raster aggregation

女生的网名这么多〃 提交于 2019-12-11 07:05:46
问题 Let's assume I have a raster representing land use classes in a certain resolution. I have to aggregate this raster with R to a coarser resolution and a modal value approach, in order to have the most dominating cell value in the coarser raster. This is easily achieved with m <- aggregate(r, fact = 3, fun = modal, na.rm = TRUE) However, I would like to weight the different land use classes – e.g. forest class (code 1) has a weight of 4 while water class (code 2) has a weight of 2 and street

Get min and max value in single query in mongodb

此生再无相见时 提交于 2019-12-11 06:56:05
问题 Considering the following Documents in "Words": [{ _id: 1, usages: 2, word: "Name" }, { _id: 2, usages: 1, word: "Street" }, { _id: 3, usages: 1, word: "House" }, { _id: 4, usages: 3, word: "Table" }, { _id: 5, usages: 3, word: "Bread" }, { _id: 6, usages: 4, word: "Door" }] How can i get all the records where the number of usages is the lowest or highest? Lowest should return id 2 and 3(and their word), highest should return id 6 with its word. I need to aggregate this data into a random

Check time series incongruencies

此生再无相见时 提交于 2019-12-11 06:18:41
问题 Let's say that we have the following matrix: x<- as.data.frame(cbind(c("A","A","A","B","B","B","B","B","C","C","C","C","C","D","D","D","D","D"), c(1,2,3,1,2,3,4,5,1,2,3,4,5,1,2,3,4,5), c(14,28,42,14,46,64,71,85,14,28,51,84,66,22,38,32,40,42))) colnames(x)<- c("ID","Visit", "Age") The first column represents subject ID, the second a list of observations and the third the age at each of this consecutive observations. Which would be the easiest way of finding visits where the age is wrong

Pandas - DataFrame aggregate behaving oddly

北城余情 提交于 2019-12-11 05:57:36
问题 Related to Dataframe aggregate method passing list problem and Pandas fails to aggregate with a list of aggregation functions Consider this dataframe import pandas as pd import numpy as np df = pd.DataFrame(index=range(10)) df['a'] = [ 3 * x for x in range(10) ] df['b'] = [ 1 -2 * x for x in range(10) ] According to the documentation for aggregate you should be able to specify which columns to aggregate using a dict like this: df.agg({'a' : 'mean'}) Which returns a 13.5 But if you try to

MySQL finding subtotals

£可爱£侵袭症+ 提交于 2019-12-11 05:46:14
问题 EDIT: I'm told that making you guys read means I get less attention. My apologies. Here's a simpler version: Bill got $100 dollars worth of items from a store. He wants to return enough of the items to get exactly $30 dollars back. The store has a Point of Return system that will help him do this. Here is the data after he scans his items: item ¦ price ¦ socks 4.00 cheap tv 22.00 book on tape 9.00 book on paper 7.00 party hats 3.00 picture frame 10.00 hammer 5.00 juicer 16.00 mysql guide 24

Aggregate initialization with curly braces

大兔子大兔子 提交于 2019-12-11 05:43:53
问题 In C++11, are the aggregates allowed to be copied with curly-braces syntax? I have the following code: struct s { int x; }; template<class T> struct holder { template<class A> holder(A&& x) : t{x} {} T t; }; Each one of the statements below works. auto s1 = s{1}; auto s2(s1); auto s3{s1}; ///NOTE : this works! However, the second statement below raises the error cannot convert 's' to 'int' in initialization . holder<s> h{5}; holder<s> h1{s{5}}; I am using gcc 4.8.2. Why do I get this error?

Aggregation in data.table by reference to column names [duplicate]

ⅰ亾dé卋堺 提交于 2019-12-11 05:35:08
问题 This question already has an answer here : Data.table meta-programming (1 answer) Closed 3 years ago . I would like to aggregate some columns by a list of columns in a data.table. However, I would like to refrain from using the column names outside the quotation marks (in the by = .(desiredColumn1, desiredColumn2) , that is). I am happy with using either the column names or the column indices. For example: library(data.table) x = as.data.table(iris) x[, sum(Sepal.Width), by = .(Sepal.Length,

R Aggregate FUN=head

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 05:26:16
问题 I would like to aggregate a table (tab) by two columns (sequence and program) to get the top row of samplesize (FUN=head). sq <- c(1,1,1,1,1,1) prog<- c('A','A','B','B','C','C') ss <- c(47,47,28,28,47,47) tab<- data.frame(sq,prog,ss) Aggregate is giving me an odd result in that if the sample size is the same for a DIFFERENT combination of sequence and program- it omits it. agg <- aggregate(cbind(sq,prog) ~ ss, data = tab, FUN=head,1,na.rm=TRUE) I'm confused why this is occurring and why it is