grouping

logical value count with summarise r

╄→гoц情女王★ 提交于 2020-11-29 14:01:09
问题 In a data frame, I have a column with Y and N values. This data frame also has an id column. I would like to create two columns, one with the total Y count and another with the total N count for each id. I tried doing this procedure with the dplyr summarise function group_by(id) %>% summarise(total_not = count(column_y_e_n == "N"), total_yes = count(column_y_e_n == "Y") but objected to the error message Error in summarise_impl(.data, dots) Any sugestion? 回答1: Slight variation on original

Using LINQ GroupBy to group by reference objects instead of value objects

匆匆过客 提交于 2020-08-26 09:56:13
问题 I want to GroupBy multiple objects in a list of records and not simply multiple values. I am having trouble getting grouping to work with reference type objects. I have a collection of objects that contain Room, Type, and DateTime. Room, Type, and DateTime all have properties associated with them. I've already added the IEquateable interface to the room and the type thinking that would be enough to with with group by. var groups = collection .Where(g => g.Stage == InventoryStage.StageA)

Get grouped comma separated values with linq

こ雲淡風輕ζ 提交于 2020-08-24 06:33:27
问题 I would like a third column "items" with the values that are grouped. var dic = new Dictionary<string, int>(); dic.Add("a", 1); dic.Add("b", 1); dic.Add("c", 2); dic.Add("d", 3); var dCounts = (from i in dic group i by i.Value into g select new { g.Key, count = g.Count()}); var a = dCounts.Where(c => c.count>1 ); dCounts.Dump(); a.Dump(); This code results in: Key Count 1 2 2 1 3 1 I would like these results: Key Count Items 1 2 a, b 2 1 c 3 1 d 回答1: var dCounts = (from i in dic group i by i