我有一个如下所示的大数据集:
Image | Length | Angel
--------------------------------
DSC_001 | 233.22 |2.00
--------------------------------
DSC_001 | 24.897 |1.2
--------------------------------
DSC_001 | 28.55 |2.87
--------------------------------
DSC_002 | 23.76 |3.71
--------------------------------
DSC_002 | 34.21 |3.21
---------------------------------
我想为每组设置Length
和Angles
的平均值(DSC_001是一组,DSC_002是另一组,等等。)
我可以在Excel中手动执行此操作,但在大约4000个数据点时需要花费大量时间。
我想知道我是如何以更智能的方式在R或Excel中执行此操作的?
答案 0 :(得分:2)
在R
中,我们可以使用dplyr
library(dplyr)
df1 %>%
group_by(image) %>%
summarise_each(funs(mean))
或data.table
library(data.table)
setDT(df1)[, lapply(.SD, mean) , by = image]
或使用aggregate
base R
aggregate(.~image, df1, FUN = mean)
答案 1 :(得分:0)
In Excel:
Image
column as decribed here.AVERAGEIF()
to compute a conditioned average with the formula: =AVERAGEIF(A2:A10,E3,B2:B10)
assuming A2:A10
is the column Image
, B2:B10
is The column of the values to calculate their mean, and E3
is the cell where the Image to calculate its' mean is stored.Here is a screenshot to clarify this:
Hope it helps ;)