group-by

Count distinct in a rxSummary

◇◆丶佛笑我妖孽 提交于 2019-12-12 02:54:00
问题 I want to count distinct values of var2 grouping by var1 in a .xdf file, I tried something like this myFun <- function(dataList) { UniqueLevel <<- unique(c(UniqueLevel, dataList$var2)) SumUniqueLevel <<- length(UniqueLevel) return(NULL) } rxSummary(formula = ~ var1, data = "DefModelo2.xdf", transformFunc = myFun, transformObjects = list(UniqueLevel = NULL), removeZeroCounts = F) Thank you in advance EDIT: Probably using RevoPemaR is the the faster way 回答1: One other option is to use

group by on scipy sparse matrix

依然范特西╮ 提交于 2019-12-12 02:45:10
问题 I have a scipy sparse matrix with 10e6 rows and 10e3 columns, populated to 1%. I also have an array of size 10e6 which contains keys corresponding to the 10e6 rows of my sparse matrix. I want to group my sparse matrix following these keys and aggregate with a sum function. Example: Keys: ['foo','bar','foo','baz','baz','bar'] Sparse matrix: (0,1) 3 -> corresponds to the first 'foo' key (0,10) 4 -> corresponds to the first 'bar' key (2,1) 1 -> corresponds to the second 'foo' key (1,3) 2 ->

SQL: COUNT() grouped results

家住魔仙堡 提交于 2019-12-12 02:41:57
问题 this is my current query: SELECT locationname, eventid FROM events GROUP BY locationname ORDER BY locationname ASC As you can see it's grouped by locationname because there are several rows with the same locationname. In the output i just need a list of "distinct" (grouped) locations but behind every location there should be the total amount of each location. So if in "events" are 4 locationsname with "Congress Center NYC" the output should be "Congress Center NYC (4)". Is there a way to

MS Version of This MySQL View with GROUP BY?

筅森魡賤 提交于 2019-12-12 02:32:43
问题 I was shown the ease that one can make a view from multiple tables, GROUPing BY an id of one of the tables in xception's awesome answer here: CREATE VIEW WHERE SELECTid = VIEWrowID Is there any way to do that in MS? Everywhere, I've read says "no", but no page gives an alternative. I don't need the counts or anything, just multiple columns from multiple tables GROUPed BY(?) a single column on one table. Thanks a lot in advance! EXAMPLE Thank-you for responding. For the view's SELECT: SELECT

mysql group by php concat

亡梦爱人 提交于 2019-12-12 02:25:05
问题 I have a table of fixtures in my DB: hometeam, awayteam, date, time I am currently using mysql_fetch_array and getting the following: hometeam awayteam date time -------------------------------------------- Blackburn Wolves 13/08/2011 3:00pm Arsenal Liverpool 13/08/2011 3:00pm etc I want to return: 13/08/2011 --------------------------- Blackburn, Wolves, 3:00pm Arsenal, Liverpool, 3:00pm etc I have tried group by date, but this just returns 1 fixture for that date which is rubbish. I have

javascript linq.js groupby

廉价感情. 提交于 2019-12-12 02:23:43
问题 I have the following JSON data in a Javascript function (it's simplified here): var data = [ { Expiry: "2013-01-02T00:00:00", EndDate: "2013-01-16T00:00:00", Category: 10, Amount: 14.53 }, { Expiry: "2013-01-02T00:00:00", EndDate: "2013-01-16T00:00:00", Category: 25, Amount: 14.86 }, { Expiry: "2013-02-06T00:00:00", EndDate: "2013-02-20T00:00:00", Category: 10, Amount: 14.43 }, { Expiry: "2013-02-06T00:00:00", EndDate: "2013-02-20T00:00:00", Category: 25, Amount: 14.76 } ]; Note: An EndDate

Select up to x rows of each group

[亡魂溺海] 提交于 2019-12-12 02:23:43
问题 With a table of: id | name | job | rank 01 john teacher 4 02 mark teacher 2 03 phil plummer 1 04 dave teacher 7 05 jim plummer 9 06 bill plummer 2 How can I select up to 2 rows of each job (if possible sorted by rank ASC in each group, so that the lowest two ranking of each group get picked). The result I'd be looking for is: 02 mark teacher 2 01 john teacher 4 03 phil plummer 1 06 bill plummer 2 This basically groups by job, with a limit to 2 and sorted by rank. I've been trying with GROUP

Python group by

一个人想着一个人 提交于 2019-12-12 02:22:37
问题 Assume that I have a set of data pair where index 0 is the value and index 1 is the type: input = [ ('11013331', 'KAT'), ('9085267', 'NOT'), ('5238761', 'ETH'), ('5349618', 'ETH'), ('11788544', 'NOT'), ('962142', 'ETH'), ('7795297', 'ETH'), ('7341464', 'ETH'), ('9843236', 'KAT'), ('5594916', 'ETH'), ('1550003', 'ETH') ] I want to group them by their type (by the 1st indexed string) as such: result = [ { type:'KAT', items: ['11013331', '9843236'] }, { type:'NOT', items: ['9085267', '11788544']

ORDER grouped values by custom rank - SQL

走远了吗. 提交于 2019-12-12 01:56:59
问题 I've been trying to order the ID's of the Objects contained in my Table. For this, I'm using the following hierarchy, which is based on the order of attributes within the 'IN' clause: ORDER BY First: ID's that match ALL the attributes: 'Solid' and 'Metal' and 'Red' Second: ID's that match the attributes: 'Solid' and 'Metal' Third: ID's that match just the attribute: 'Solid' Fourth: ID's that match attributes: 'Metal' and 'Red' Fifth: ID's that match just the attribute: 'Metal' Sixth: ID's

LINQ Expression of the Reference Property

北城余情 提交于 2019-12-12 01:56:19
问题 I want to get the LINQ Expression of the Reference Property I need to get the Lambda Expression as groupCol=>groupCol.Role.Name I have tried with the expression but not succeeded , this will work with groupCol=>groupCol.MenuText but not with reference types var menu = Expression.Parameter(typeof(Menu), "groupCol"); // getting Role.Name' is not a member of type exception var menuProperty = Expression.PropertyOrField(menu, property); var lambda = Expression.Lambda<Func<Menu, string>>