Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从r中的第二行开始聚合_R_Aggregate - Fatal编程技术网

从r中的第二行开始聚合

从r中的第二行开始聚合,r,aggregate,R,Aggregate,我想对多个列使用聚合函数,结果很好 唯一的问题是,我希望它从每列的第二行开始计算,忽略每列的标题 这是我的职责: agg <- aggregate(list(museNumeric$Delta_TP9, museNumeric$Delta_AF7, museNumeric$Delta_AF8, museNumeric$Delta_TP10), by = list(museNumeric$intTimestamp), median) 谢谢你的帮助 看起来您有一个data.frame要在其上

我想对多个列使用聚合函数,结果很好

唯一的问题是,我希望它从每列的第二行开始计算,忽略每列的标题

这是我的职责:

agg <- aggregate(list(museNumeric$Delta_TP9, museNumeric$Delta_AF7, museNumeric$Delta_AF8, museNumeric$Delta_TP10), by = list(museNumeric$intTimestamp), median)
谢谢你的帮助

看起来您有一个data.frame要在其上执行此操作,我们将其称为df。以下是data.table方法:

library(data.table)
dt <- as.data.table(df)


d[2:nrow(dt), list(new_value = median(column_name)), by = list(intTimestamp)]
您可以将多个函数应用于多列—它们不必都是平均值,也不必通过多列进行聚合—顺序问题:

> dt[2:.N, list(new_disp = mean(disp), median_carb = median(carb)), by = list(gear, cyl)]
   gear cyl new_disp median_carb
1:    4   6      225           2
2:    4   4      225           2
3:    3   6      225           2
4:    3   8      225           2
5:    3   4      225           2
6:    5   4      225           2
7:    5   8      225           2
8:    5   6      225           2

如前所述,您需要将列标题设置为名称。 此外,您应该在R中使用dataframe公共结构

# this is a data.frame
df <- data.frame(
    a = 1:10
    , b = 11:20
    , c = 21:30
)
在这里你可以做

df %>%
    summarise_all(median)
…也就是说

take the dataframe (df) then (%>%)
    apply a function (median) to all columns (summarise_all)

欢迎来到堆栈溢出。这是r吗?请给它贴上r标签。另外,请修复您的代码块格式。是的,它是r,谢谢您的评论。我做了编辑。你需要提供样本数据,否则我们只能猜测你的专栏中的数据类型。dput head museNumeric将是一个良好的开端。列标题不应在一行中,而应在数据框的名称中。请务必共享dput结果,以便我们可以看到您的数据结构发生了什么。如果dputheadmuseNumeric太长,请使用dputdroplevelsheadmuseNumeric。
df %>%
    summarise_all(median)
take the dataframe (df) then (%>%)
    apply a function (median) to all columns (summarise_all)