如何将()仅应用于rowsums()> 0
关于如何将函数应用于至少1个值大于0的行的行,任何想法吗?
我尝试过:
batch4 =
raw_mat[,all_conds == "LR140 AM"] %>%
apply(., 1, FUN = function(x) ifelse(sum(x) > 0, zCompositions::cmultRepl(., output = "p-counts", z.warning = 1), x))
Error in rowSums(x) : 'x' must be an array of at least two dimensions
但是,当时的lowsums似乎只占据一行的1个元素吗?
> batch4 =
+ raw_mat[,all_conds == "LR140 AM"] %>%
+ rowwise() %>%
+ mutate(across(where(rowSums(.) > 0), zCompositions::cmultRepl(., output = "p-counts", z.warning = 1)))
Error in `mutate()`:
! Problem while
computing `..1 =
across(...)`.
ℹ The error occurred in row
0.
Caused by error in `zCompositions::cmultRepl()`:
! Row(s) containing all zeros/unobserved values were found (check it out using zPatterns).
Run `rlang::last_error()` to see where the error occurred.
因此,在这种情况下,由于CmuletrePl还获得“仅零”行,因此看起来rowsums滤波器无法正常工作。
any thoughts on how to apply a function to only row where there is at least 1 value more than 0?
I tried:
batch4 =
raw_mat[,all_conds == "LR140 AM"] %>%
apply(., 1, FUN = function(x) ifelse(sum(x) > 0, zCompositions::cmultRepl(., output = "p-counts", z.warning = 1), x))
Error in rowSums(x) : 'x' must be an array of at least two dimensions
but it seems rowSums is only taking 1 element of the row at the time?
> batch4 =
+ raw_mat[,all_conds == "LR140 AM"] %>%
+ rowwise() %>%
+ mutate(across(where(rowSums(.) > 0), zCompositions::cmultRepl(., output = "p-counts", z.warning = 1)))
Error in `mutate()`:
! Problem while
computing `..1 =
across(...)`.
ℹ The error occurred in row
0.
Caused by error in `zCompositions::cmultRepl()`:
! Row(s) containing all zeros/unobserved values were found (check it out using zPatterns).
Run `rlang::last_error()` to see where the error occurred.
So in this case it looks like the rowSums filter is not working properly, as cmultRepl gets also "only zeros" rows.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论