aggregate

SQL Server 2005/2008 Group By statement with parameters without using dynamic SQL?

若如初见. 提交于 2020-01-21 09:56:27
问题 Is there a way to write SQL Server Stored Procedure which to be strongly typed ( i.e. returning known result set of columns ) and having its group statement to be dynamic. Something like: SELECT SUM( Column0 ) FROM Table1 GROUP BY @MyVar I tried the following also: SELECT SUM( Column0 ) FROM Table1 GROUP BY CASE @MyVar WHEN 'Column1' THEN Column1 ELSE Column2 The second statement works only in scenarios where the db types of Column1 and Column2 are the same. If they are not the SQL engine

Getting different results using aggregate() and sum() functions in R

China☆狼群 提交于 2020-01-17 07:05:30
问题 I'm trying to get a summary data frame of the total quantities of the variables prop.damage and crop.damage by STATE variable using the aggregate() function in R with the following code: stormdata$prop.damage <- with(stormdata, ifelse(PROPDMGEXP == 'K', (PROPDMG * 10^3), ifelse(PROPDMGEXP == 'M', (PROPDMG * 10^6), ifelse(PROPDMGEXP == 'B', (PROPDMG * 10^9), NA)))) stormdata$crop.damage <- with(stormdata, ifelse(CROPDMGEXP == 'K', (CROPDMG * 10^3), ifelse(CROPDMGEXP == 'M', (CROPDMG * 10^6),

Getting different results using aggregate() and sum() functions in R

淺唱寂寞╮ 提交于 2020-01-17 07:03:14
问题 I'm trying to get a summary data frame of the total quantities of the variables prop.damage and crop.damage by STATE variable using the aggregate() function in R with the following code: stormdata$prop.damage <- with(stormdata, ifelse(PROPDMGEXP == 'K', (PROPDMG * 10^3), ifelse(PROPDMGEXP == 'M', (PROPDMG * 10^6), ifelse(PROPDMGEXP == 'B', (PROPDMG * 10^9), NA)))) stormdata$crop.damage <- with(stormdata, ifelse(CROPDMGEXP == 'K', (CROPDMG * 10^3), ifelse(CROPDMGEXP == 'M', (CROPDMG * 10^6),

How to calculate cumulative proportion of Likert-type responses in r?

 ̄綄美尐妖づ 提交于 2020-01-16 09:07:51
问题 I am trying to provide a basic summary of my Likert-type (5-point) survey results. I know how we can use basic mathematical functions across subgroups using the aggregate function. For instance, I can produce means of each item across subgroups but I do not know how to get a percentage of occurrence of more than 2 possible responses across all items. I have always used SPSS to aggregate the proportion of positive responses (say 4 and 5) for each item across subgroups. So, as a result, I

mongo的聚合操作

杀马特。学长 韩版系。学妹 提交于 2020-01-16 02:10:09
对图7-1所示的数据集exampledata1,使用聚合操作实现以下功能: (1)不返回_id字段,只返回age和sex字段。 (2)所有age大于28的记录,只返回age和sex。 (3)在$match返回的字段中,添加一个新的字段“hello”,值为“world”。 (4)在$match返回的字段中,添加一个新的字段“hello”,值复制age的值。 (5)在$match返回的字段中,把age的值修改为一个固定字符串。 (6)把user.name和user.user_id变成普通的字段并返回。 (7)在返回的数据中,添加一个字段“hello”,值为“$normalstring”,再添加一个字段“abcd”,值为1。 “$match”可以筛选出需要的记录,那么如果想只返回部分字段,又应该怎么做呢?这时就需要使用关键字“$project”。 返回部分字段 首先用“$project”来实现一个已经有的功能——只返回部分字段。格式如下: collection . aggregate ([{ '$project' : {字段过滤语句}}]) 这里的字段过滤语句与“find()”第2个参数完全相同,也是一个字典。字段名为Key,Value为1或者0(需要的字段Value为1,不需要的字段Value为0)。 例如,对于图7-1所示的数据集,不返回“_id”字段,只返回age和sex字段

How to subset or aggregate large amounts of data so I can make separate pie charts

非 Y 不嫁゛ 提交于 2020-01-15 12:18:05
问题 My data looks like this: Trip_Set sex 119_4 hembra 119_4 hembra 119_7 hembra 161_7 macho 193_8 hembra 255_7 macho 271_6 hembra 271_6 macho 271_6 hembra 328_7 hembra 403_3 hembra 428_2 hembra 655_4 hembra As you can see, each Trip_Set has a number of males or females (some just have one). I wish to make a separate pie chart for each trip set to show the ratio of males to females for each. This is just a snippet of my dataset (the real one is much larger with hundreds of Trip_Sets). My code for

Oracle SQL - Generate aggregate rows for certain rows using select

断了今生、忘了曾经 提交于 2020-01-15 09:17:08
问题 I have a table like below. |FILE| ID |PARENTID|SHOWCHILD|CAT1|CAT2|CAT3|TOTAL| |F1 | A1 | P1 | N | 3 | 2 | 6 | 11 | |F2 | A2 | P2 | N | 4 | 7 | 3 | 14 | |F3 | A3 | P1 | N | 3 | 1 | 1 | 5 | |F4 | LG1| | Y | 6 | 3 | 7 | 16 | |F5 | LG2| | Y | 4 | 7 | 3 | 14 | Now, Is it possible if I want to find the total (ie) aggregate of cat1, cat2, cat3 & total only for rows which has showChild as 'Y' and add that to the resultset. |Tot| Res | Res | N | 10 | 10 | 10 | 30 | Expected final output: |FILE| ID

r collapsing data from multiple columns into one

六月ゝ 毕业季﹏ 提交于 2020-01-15 06:06:08
问题 I know there are many questions on this topic so I apologize if this is a duplicate question. I'm trying to collapse multiple columns in a data set into one column: Assuming this is the structure of the dataset I am working with, df <- data.frame( cbind( variable_1 = c('Var1', NA, NA,'Var1'), variable_2 = c('Var2', 'No', NA, NA), variable_3 = c(NA, NA, 'Var3', NA), variable_4 = c(NA, 'Var4', NA, NA), variable_5 = c(NA, 'No', 'Var5', NA), variable_6 = c(NA, NA, 'Var6', NA) )) variable_1

how to perform sum and count on dataframe in R

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-15 03:58:08
问题 I have a dataframe with ID, type, and the area I would like to perform two operations at once ID Type Area 1 Aa 0.02 2 Ag 0.12 2 Ag 0.14 2 Ag 0.80 2 Bm 0.20 2 Xm 0.13 The expected outcome is ID Type count area 1 Aa 1 0.02 2 Ag 3 1.06 (sum) 2 Bm 1 0.20 2 Xm 1 0.13 I have up to 100-150 ID and type, count and basal area varies for each type with the same ID, what would be the best approach to perform sum and count same time and keep type and ID in dataframe? Thanks 回答1: 1) Base R -- aggregate

DataRow[] Aggregate Functions C#

杀马特。学长 韩版系。学妹 提交于 2020-01-14 10:32:37
问题 I have an array of DataRow objects in my C# project which I would like to Sum various fields from. Instead of running through each row and totalling my own sums I noticed the DataRow[].Sum<> function but I am struggling to find any resources on the net on how to use it. Any pointers in the right direction would be very helpful :) Removed code example as it was wrong! All now works fine - the link helped cheers Marc. 回答1: That is the LINQ Sum ; and can be used: var sum = rows.Sum(row => row