我有一个集群数据的数据框,我正在按集群对其进行聚合以提供摘要数据。
我想基于簇数n()创建一个新列,然后对一系列变量进行均值和求和:
# A tibble: 6 x 2
carb cnt
<dbl> <int>
1 1 7
2 2 10
3 3 3
4 4 10
5 6 1
6 8 1
# does not work, returns error message:
> Error in summarise_impl(.data, dots) : Evaluation error: object
> 'disp' not found. In addition: Warning message: In mean.default(mpg) :
> argument is not numeric or logical: returning NA
nums <- c("mpg", "disp", "cyl")
mtcars %>% group_by(carb) %>% summarise(cnt = n()) %>% summarise_at(.vars = nums,
funs(mean, sum))
看起来像这样:
string thejson = @"{
""error_code"": 0,
""access_token"": ""*******************"",
""expires_in"": 7200
}";
JObject jobj = JObject.Parse(thejson);
string theToken = jobj["access_token"].ToString();
目标是上面的tbl,但新列cnt是每组中的观察值。
答案 0 :(得分:0)
我们可以mutate
通过'carb'创建'cn't,然后在进行summarise_at
mtcars %>%
group_by(carb) %>%
mutate(cnt = n()) %>%
group_by(cnt, add = TRUE) %>%
summarise_at(.vars = nums, funs(mean, sum))