distinct-values

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

selecting random value from column based on distinct values

心已入冬 提交于 2019-12-11 05:29:24
问题 I have following data in table :- | item | rate | ------------------- | a | 50 | | a | 12 | | a | 26 | | b | 12 | | b | 15 | | b | 45 | | b | 10 | | c | 5 | | c | 15 | and i need a query which return following output : | item no | rate | ------------------ | a | 12 | --from (26 , 12 , 50) | b | 45 | --from (12 ,15 , 45 , 10) | c | 5 | --from (5 , 15) i.e item_no should be distinct and with randomly one rate value.. Thanks in advance 回答1: WITH CTE AS ( SELECT DISTINCT item FROM T ) SELECT CTE

sql join - only select top row from 2nd table

こ雲淡風輕ζ 提交于 2019-12-11 04:39:50
问题 Bit of an sql noob, have a list in table a of customercodes/phone numbers, and table b has all the call records. I want to select the most recent call from table b for each of the customercodes/phone numbers in table a. So far I have: SELECT A.CustomerCode, A.PhoneNumber, B.StartTime FROM tableA A INNER JOIN tableB B ON ( A.PhoneNumber = B.PhoneNumber AND A.CustomerCode = B.CustomerCode ) ORDER BY A.CustomerCode, A.CLI, B.StartTime DESC But that is bringing up all the results from TableB. I

Efficiently find unique elements in 2-dim array T[][] in C#

安稳与你 提交于 2019-12-11 03:24:54
问题 One solution to extract unique values would be to apply Array[i].Distinct() to each row and then form the list of all the unique elements from each row. Then we can repeat for this list List.Distinct() . But is there more efficient way how to create T[] UniqueValues out of T[][] Data ? Thanks 回答1: var distinct = array.SelectMany(a => a).Distinct().ToArray(); This simply flattens the nested arrays into a sequence and calls Distinct to find the distinct elements. The call to ToArray may be

How to make a dictionary from a text file with python

穿精又带淫゛_ 提交于 2019-12-11 03:18:16
问题 My file looks like this: aaien 12 13 39 aan 10 aanbad 12 13 14 57 58 38 aanbaden 12 13 14 57 58 38 aanbeden 12 13 14 57 58 38 aanbid 12 13 14 57 58 39 aanbidden 12 13 14 57 58 39 aanbidt 12 13 14 57 58 39 aanblik 27 28 aanbreken 39 ... I want to make a dictionary with key = the word (like 'aaien') and the value should be a list of the numbers that are next to it. So it has to look this way: {'aaien': ['12, 13, 39'], 'aan': ['10']} This code doesn't seem to work. document = open('LIWC_words

R: calculate number of distinct categories in the specified time frame

杀马特。学长 韩版系。学妹 提交于 2019-12-08 04:13:36
问题 here's some dummy data: user_id date category 27 2016-01-01 apple 27 2016-01-03 apple 27 2016-01-05 pear 27 2016-01-07 plum 27 2016-01-10 apple 27 2016-01-14 pear 27 2016-01-16 plum 11 2016-01-01 apple 11 2016-01-03 pear 11 2016-01-05 pear 11 2016-01-07 pear 11 2016-01-10 apple 11 2016-01-14 apple 11 2016-01-16 apple I'd like to calculate for each user_id the number of distinct categories in the specified time period (e.g. in the past 7, 14 days), including the current order The solution

selecting a distinct combination of 2 columns in SQL

倾然丶 夕夏残阳落幕 提交于 2019-12-06 08:17:58
When i run a select after a number of joins on my table I have an output of 2 columns and I want to select a distinct combination of col1 and col2 for the rowset returned. the query that i run will be smthing like this: select a.Col1,b.Col2 from a inner join b on b.Col4=a.Col3 now the output will be somewhat like this Col1 Col2 1 z 2 z 2 x 2 y 3 x 3 x 3 y 4 a 4 b 5 b 5 b 6 c 6 c 6 d now I want the output should be something like follows 1 z 2 y 3 x 4 a 5 b 6 d its ok if I pick the second column randomly as my query output is like a million rows and I really dnt think there will be a case where

How to aggregate count of unique values of categorical variables in R

女生的网名这么多〃 提交于 2019-12-06 05:41:23
问题 Suppose I have a data set data : x1 <- c("a","a","a","a","a","a","b","b","b","b") x2 <- c("a1","a1","a1","a1","a1","a1","b1","b1","b2","b2") data <- data.frame(x1,x2) x1 x2 a a1 a a1 a a2 a a1 a a2 a a3 b b1 b b1 b b2 b b2 I want to find the number of unique values of x1 corresponding to x2 For example a has only 3 unique values ( a1,a2 and a3 ) and b has 2 values ( b1 and b2 ) I used aggregate(x1~.,data,sum) but it did not work since these are factors, not integers. Please help 回答1: Try

druid vs Elasticsearch

我的梦境 提交于 2019-12-05 10:54:08
I'm new to druid. I've already read "druid VS Elasticsearch", but I still don't know what druid is good at. Below is my problem: I have a solr cluster with 70 nodes. I have a very big table in solr which has 1 billion rows, and each row has 100 fields. The user will use different combinations range query of fields (20 combinations at least in one query) to count the distinct number of customer id, but the solr's distinct count algorithm is very slow and uses a lot of memory, so if the query result is more than 200 thousand, the solr's query node will crash. Does druid has better performance

Trying to sum distinct values SQL

ⅰ亾dé卋堺 提交于 2019-12-05 03:52:18
I'm having trouble coming up with a value for a cell in SSRS, which should be a sum of distinct values. I have a SSRS report that looks similar to the below screenshot: I'm having trouble getting the value in red ($11.25). I basically need to sum the Ship Cost, based on distinct Tracking #s. So there are two distinct tracking #s, one with a Ship Cost of $5.25 and the other $6.00, so the total displayed in red should be $11.25. But I cannot achieve this in SSRS and can't figure it out in the SQL query either. I'm thinking a subquery like (and I know the below is not valid SQL): (SELECT SUM(