aggregate

lapply aggregate columns in multiple dataframes R

走远了吗. 提交于 2021-02-20 04:16:32
问题 I have several dataframes in a list in R. There are entries in each of those DF I would like to summarise. Im trying to get into lapply so that would be my preferred way (though if theres a better solution I would be happy to know it and why). My Sample data: df1 <- data.frame(Count = c(1,2,3), ID = c("A","A","C")) df2 <- data.frame(Count = c(1,1,2), ID = c("C","B","C")) dfList <- list(df1,df2) > head(dfList) [[1]] Count ID 1 1 A 2 2 A 3 3 C [[2]] Count ID 1 1 C 2 1 B 3 2 C I tried to

lapply aggregate columns in multiple dataframes R

試著忘記壹切 提交于 2021-02-20 04:16:08
问题 I have several dataframes in a list in R. There are entries in each of those DF I would like to summarise. Im trying to get into lapply so that would be my preferred way (though if theres a better solution I would be happy to know it and why). My Sample data: df1 <- data.frame(Count = c(1,2,3), ID = c("A","A","C")) df2 <- data.frame(Count = c(1,1,2), ID = c("C","B","C")) dfList <- list(df1,df2) > head(dfList) [[1]] Count ID 1 1 A 2 2 A 3 3 C [[2]] Count ID 1 1 C 2 1 B 3 2 C I tried to

aggregate less efficient than loops?

旧街凉风 提交于 2021-02-19 02:48:27
问题 I was trying to do this operation on a big table, to count rows with different combinations of a and b in a data.table X. Y <- aggregate(c ~ a+b,X,length) And it was taking forever (I stopped after 30 min) though RAM usage was still. Then I tried to loop manually through values of b and aggregate only on a (technically still aggregating on b but with a single value of b every time) : sub_agg <- list() unique_bs <- unique(X$b) for (b_it in unique_bs){ sub_agg[[length(sub_agg)+1]] <- aggregate

Subtracting values group-wise by the average of each group in R

。_饼干妹妹 提交于 2021-02-17 05:19:27
问题 I am trying to subtract group means from each group's values. For example: > x <- data.frame('gene' = c('A','A','A','B','B','C','C','C'),'value' = c(32.3,31,30.5,25,22.1,20.5,21.2,19.8)) > x gene value 1 A 32.3 2 A 31.0 3 A 30.5 4 B 25.0 5 B 22.1 6 C 20.5 7 C 21.2 8 C 19.8 I can find the group means: > aggregate(x[,2],list(x$gene),mean) Group.1 x 1 A 31.26667 2 B 23.55000 3 C 20.50000 How do I subtract the "value" in x by the corresponding group mean? My desire result is as follow: gene value

C++ aggregates have no virtual functions?

这一生的挚爱 提交于 2021-02-15 20:58:46
问题 In C++, an aggregate is (taken from 8.5.1p1 of the language spec) an array or a class (Clause 9) with no user-provided constructors (12.1), no private or protected non-static data members (Clause 11), no base classes (Clause 10), and no virtual functions (10.3). So, #1 is not an aggregate, but #2 is an aggregate. Why is #1 not an aggregate aswell? struct A { virtual void bark() { } int a; }; // #1 struct B { A b; }; // #2 回答1: Why is #1 not an aggregate aswell? Because the standard definition

C++ aggregates have no virtual functions?

為{幸葍}努か 提交于 2021-02-15 20:51:49
问题 In C++, an aggregate is (taken from 8.5.1p1 of the language spec) an array or a class (Clause 9) with no user-provided constructors (12.1), no private or protected non-static data members (Clause 11), no base classes (Clause 10), and no virtual functions (10.3). So, #1 is not an aggregate, but #2 is an aggregate. Why is #1 not an aggregate aswell? struct A { virtual void bark() { } int a; }; // #1 struct B { A b; }; // #2 回答1: Why is #1 not an aggregate aswell? Because the standard definition

Collapse / concatenate / aggregate multiple columns to a single comma separated string within each group

爱⌒轻易说出口 提交于 2021-02-13 17:07:17
问题 This is an extension to post Collapse / concatenate / aggregate a column to a single comma separated string within each group Goal: aggregate multiple columns according to one grouping variable and separate individual values by separator of choice. Reproducible example: data <- data.frame(A = c(rep(111, 3), rep(222, 3)), B = c(rep(c(100), 3), rep(200,3)), C = rep(c(1,2,NA),2), D = c(15:20), E = rep(c(1,NA,NA),2)) data A B C D E 1 111 100 1 15 1 2 111 100 2 16 NA 3 111 100 NA 17 NA 4 222 200 1

Collapse / concatenate / aggregate multiple columns to a single comma separated string within each group

最后都变了- 提交于 2021-02-13 17:06:23
问题 This is an extension to post Collapse / concatenate / aggregate a column to a single comma separated string within each group Goal: aggregate multiple columns according to one grouping variable and separate individual values by separator of choice. Reproducible example: data <- data.frame(A = c(rep(111, 3), rep(222, 3)), B = c(rep(c(100), 3), rep(200,3)), C = rep(c(1,2,NA),2), D = c(15:20), E = rep(c(1,NA,NA),2)) data A B C D E 1 111 100 1 15 1 2 111 100 2 16 NA 3 111 100 NA 17 NA 4 222 200 1

Collapse / concatenate / aggregate multiple columns to a single comma separated string within each group

不打扰是莪最后的温柔 提交于 2021-02-13 17:05:33
问题 This is an extension to post Collapse / concatenate / aggregate a column to a single comma separated string within each group Goal: aggregate multiple columns according to one grouping variable and separate individual values by separator of choice. Reproducible example: data <- data.frame(A = c(rep(111, 3), rep(222, 3)), B = c(rep(c(100), 3), rep(200,3)), C = rep(c(1,2,NA),2), D = c(15:20), E = rep(c(1,NA,NA),2)) data A B C D E 1 111 100 1 15 1 2 111 100 2 16 NA 3 111 100 NA 17 NA 4 222 200 1

Collapse / concatenate / aggregate multiple columns to a single comma separated string within each group

╄→гoц情女王★ 提交于 2021-02-13 17:04:11
问题 This is an extension to post Collapse / concatenate / aggregate a column to a single comma separated string within each group Goal: aggregate multiple columns according to one grouping variable and separate individual values by separator of choice. Reproducible example: data <- data.frame(A = c(rep(111, 3), rep(222, 3)), B = c(rep(c(100), 3), rep(200,3)), C = rep(c(1,2,NA),2), D = c(15:20), E = rep(c(1,NA,NA),2)) data A B C D E 1 111 100 1 15 1 2 111 100 2 16 NA 3 111 100 NA 17 NA 4 222 200 1