如何将()仅应用于rowsums()> 0

发布于 2025-01-19 18:04:13 字数 945 浏览 2 评论 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文