The following objects are masked from 'package:base': ## ## intersect, setdiff, setequal, union rowwise 按照行的形式,对行进行操作 # 按照行实现两列的行求和 iris[,1:4] %>% rowwise() %>% mutate(total = sum(c(Sepal.Length, Sepal.Width ))) %>% head() ## # A tibble: 6 x 5 ## # Rowwise: ## Sepal.Length Sepal.Width Petal.Length Petal.Width prevent printing of the R code that generated the plot. c_across()选择 # 从iris中选择数字列,并进行计算 iris %>% rowwise () %>% mutate(total = sum(c_across(where(is.numeric)))) %>% head() ## # A tibble: 6 x 6 ## # Rowwise
但有时候我们也需要对某行做一些操作,dplyr中现在提供了rowwise()函数快速执行对行的操作。 简介 library(dplyr, warn.conflicts = FALSE) “rowwise()和group_by()很像,本身不做任何操作,但是使用了rowwise之后,再和mutate() df <- tibble(x = 1:2, y = 3:4, z = 5:6) df %>% rowwise() ## # A tibble: 2 × 3 ## # Rowwise: ## df %>% rowwise() %>% mutate(m = mean(c(x, y, z))) ## # A tibble: 2 × 4 ## # Rowwise: ## x rf <- df %>% rowwise(id) 计算加和: rf %>% mutate(total = sum(c(w, x, y, z))) ## # A tibble: 6 × 6 ## # Rowwise
你可以使用 rowwise() 创建它: df <- tibble(x = 1:2, y = 3:4, z = 5:6) df %>% rowwise() #> # A tibble: 2 x 3 #> 6 与 group_by() 类似, rowwise() 本身并不进行任何的操作,它仅改变其他动词操作如何工作。 df %>% rowwise() %>% mutate(l = length(x)) #> # A tibble: 3 x 2 #> # Rowwise: #> x ❞ 建模 rowwise() 数据框允许我们以一种特别优雅的方式解决很多的建模问题。 () rowwise() 也被质疑了很长一段时间,部分原因是我不明白有多少人需要通过本地能力来计算每一行的多个变量的摘要。
= ind2sub(size(R), i); R.sum() // sum(R(:)) R.colwise().sum() // sum(R) R.rowwise sum(R, 2) or sum(R')' R.prod() // prod(R(:)) R.colwise().prod() // prod(R) R.rowwise // trace(R) R.all() // all(R(:)) R.colwise().all() // all(R) R.rowwise ) // all(R, 2) R.any() // any(R(:)) R.colwise().any() // any(R) R.rowwise
下面我们用dplyr中的rowwise操作实现这一过程,当然还有其他方法,选择自己喜欢的即可。 group_list == "UC"] normal <- colnames(exprSet)[group_list == "normal"] logfc_df <- exprSet %>% rowwise genesymbol = rownames(exprSet)) %>% arrange(desc(logfc)) head(logfc_df) ## # A tibble: 6 × 4 ## # Rowwise
dat<-read_excel("data/20230521/figure1c.xlsx") head(dat) plotrix::std.error(c(1,2,3)) dat %>% rowwise std_error=plotrix::std.error(c(rep1,rep2,rep3))) %>% ungroup() -> new.dat 作图代码 dat %>% rowwise
as.integer(Days.to.Date.of.Last.Contact)) %>% # Find max time between all days (ignoring missings) rowwise prad.primary.solid.tumor) %>% as.data.frame %>% # Find max time between all days (ignoring missings) rowwise colData(skcm.metastatic) %>% as.data.frame %>% # Find max time between all days (ignoring missings) rowwise ydata.raw <- colData(skcm) %>% as.data.frame %>% # Find max time between all days (ignoring missings) rowwise
计算z-score library(tidyverse) library(stringr) dat01 %>% rowwise() %>% mutate(mean_value = mean
4 base_data <- data %>% group_by(group) %>% summarize(start=min(id), end=max(id) - 1) %>% rowwise () %>% mutate(title=mean(c(start, end))) # > head(base_data) # # A tibble: 4 x 4 # # Rowwise: # group
0, "grey35", "grey85"), pal[severity + 1]), treat_case = 2 - study_id %% 2) %>% # 计算治疗案例 rowwise
Eigen::MatrixXf new_x(5, 2); new_x << 1, 1, 1, 2, 1, 3, 1, 4, 1, 5; auto new_y = new_x.array().rowwise ); std::cout << "Predicted values : \n" << new_y << std::endl; auto new_y_norm = new_x.array().rowwise
group_by(Category) %>% summarize(start = min(seq_id), end = max(seq_id) - empty_nrow) %>% rowwise
训练dense层用Adam,训练embedding table用 Rowwise Adagrad。
(2,3); mat << 1,2,3, 4,5,6; std::cout << mat.colwise().maxCoeff(); // output: 4, 5, 6 // mat.rowWise
= ind2sub(size(R), i); R.sum() // sum(R(:)) R.colwise().sum() // sum(R) R.rowwise sum(R, 2) or sum(R')' R.prod() // prod(R(:)) R.colwise().prod() // prod(R) R.rowwise // trace(R) R.all() // all(R(:)) R.colwise().all() // all(R) R.rowwise ) // all(R, 2) R.any() // any(R(:)) R.colwise().any() // any(R) R.rowwise
= "potatoes") %>% select(-crop) %>% pivot_wider(names_from = year, values_from = "yield") %>% rowwise is.na(yield) ) %>% pivot_wider(names_from = year, values_from = yield) %>% rowwise() %>% mutate Denmark" ) ) %>% pivot_wider(names_from = year, values_from = yield) %>% select(-crop) %>% rowwise
estimate), LL = exp(estimate - 1.96*std.error), UL = exp(estimate + 1.96*std.error)) %>% rowwise estimate), LL = exp(estimate - 1.96*std.error), UL = exp(estimate + 1.96*std.error)) %>% rowwise estimate), LL = exp(estimate - 1.96*std.error), UL = exp(estimate + 1.96*std.error)) %>% rowwise
= "missing")# Microbiome databias_corr_species <- bias_corr_species %>% dplyr::rowwise() %>% dplyr
├─dplyr::rowwise(.) 17. ├─dplyr::select(...) 18. └─dplyr:::select.data.frame(...)
<< m.colwise().lpNorm<1>().maxCoeff() << endl; cout << "infty-norm(m) = " << m.cwiseAbs().<em>rowwise</em> ().sum().maxCoeff() << " == " << m.<em>rowwise</em>().lpNorm<1>().maxCoeff() << endl; } 输出: 1-norm MatrixXf mat(2,4); mat << 1, 2, 6, 9, 3, 1, 7, 2; std::cout << "Row's maximum: " << std::endl << mat.rowwise