【发布时间】:2014-09-02 01:31:35
【问题描述】:
我有两个向量:
x <- c(1,1,1,1,1, 2,2,2,3,3, 3,3,3,4,4, 5,5,5,5,5 )
y <- c(2,2,1,3,2, 1,4,2,2,NA, 3,3,3,4,NA, 1,4,4,2,NA)
这个问题 (Conditional calculating the numbers of values in column with R, part2) 讨论了如何为每个 x(从 1 到 5)和每个 y(从1-4)。
让我们按组拆分X:如果x<=2,则组I;如果2<x<=3,组II;如果3<X<=5,则分组III。我需要按组和y 的每个值查找x 中不同值的数量。我还需要在同一组中找到x 中这些值的平均值。输出应采用以下格式:
y x Result 1 (the number of distinct numbers in X); Result 2 (the mean)
1 I ...
1 II ...
1 III ...
...
4 I ...
4 II ...
4 III ...
【问题讨论】:
标签: r aggregation