下面的代码和数据源主要来自:https://stackoverflow.com/questions/51063842/create-multiple-columns-in-summarize,以计算分位数为例。 > library(dplyr) > library(tidyr) > > Z<-data.frame(x=runif(1000,min=0,max=20))%>% + mutate(y = rnorm(n(), mean = sin(x))) %>% + group_by(x.cat...
dplyr提供的功能标准评估版本(例如regroup, summarize_each_),可以简化程序中使用的dplyr (注意程序中使用的data.table是绝对有可能,只是需要一些认真思考,置换 / 报价,等等,至少据我所知) 我运行了自己的基准测试 ,发现这两个软件包在 “拆分应用合并” 样式分析中具有可比性,只是当有非常多的组...
#gather Gather columns into key-value pairs;students2为数据集,grade为第一列,不参与gather;剩下的列名及数据作为键值对放入sex_class(key)和count(value)下。 接下来seperate将sex_class列分成俩列。separate :Separate one column into multiple columns. (2)spread(): # spread:Spread a key-value pair ac...
使用rowSums对每行求和(rowwise适用于任何聚合,但速度较慢)
Issue described (with solutions) here but I feel like this would be an excellent feature, contingent on it not being too nightmarish to program. Currently summarise_at/summarise_if/summarize_at/summarize_if can only be used once, on a si...
summarize_at(.tbl, .vars, .funs,..., .cols =NULL) 参数 .tbl tbl对象。 .funs 函数fun、 quosure 样式 lambda~ fun(.)或任一形式的列表。 ... .funs中函数调用的附加参数。这些仅在tidy dots支持下评估一次。 .predicate 应用于列或逻辑向量的谓词函数。选择.predicate为或返回TRUE的变量。该参数传递...
或者,如果我们只需要使用tidyverse函数,则将其转换为'long'格式,其中包含gather,summarize和row,并获得...
diamonds %>% filter(cut != "Fair") %>% group_by(cut) %>% summarize( AvgPrice = mean(price), MedianPrice = as.numeric(median(price)), Count = n() ) %>% arrange(desc(Count)) Even if you've never seen dplyr before (or even R!), you can still get the gist of what's ha...
使用rowSums对每行求和(rowwise适用于任何聚合,但速度较慢)
PD: for the sake of understanding why I need this, I have another data frame with multiple columns with complex names that need to be "summarised", that's why I can't put one by one on the summarise command. What I want is to put a vector there to calculate the probs of each co...