我記得使用這個函數split_by之前從包purrr
。現在,當我嘗試訪問它時,它說無法找到連接點Split_by
。我試着在包purrr
上做一個ls,我找不到那裏的功能。有沒有其他方法可以在包裝中達到目的?找不到函數Split_by in R在purrr包
0
A
回答
0
看這裏爲purrr 0.2.3
https://cran.r-project.org/web/packages/purrr/news.html
order_by(),sort_by()和split_by()已被刪除。 order_by() 與dplyr :: order_by()衝突,並且整個系列不覺得 有用。改用t((#217)。
這裏是purrr 0.2.2
原代碼:
split_by <- function(.x, .f, ...) {
vals <- map(.x, .f, ...)
split(.x, simplify_all(transpose(vals)))
}
和原來的例子:
l2 <- rerun(5, g = sample(2, 1), y = rdunif(5, 10))
l2 %>% split_by("g") %>% str()
使用tibbles代替
我理解的方向「使用tibbles相反「這樣:
您的列表中有幾個項目共享相同的結構,因此名單是不是合適的結構,你可以轉換爲tibble
尊重"one row by observation, one column by variable"
整齊規則,以下前面的例子:
t2 <- as_tibble(transpose(l2)) %>% mutate(g=unlist(g))
然後你可以把它分解:
split(t2,t2$g)
# $`1`
# # A tibble: 3 x 2
# g y
# <int> <list>
# 1 1 <dbl [5]>
# 2 1 <dbl [5]>
# 3 1 <dbl [5]>
#
# $`2`
# # A tibble: 2 x 2
# g y
# <int> <list>
# 1 2 <dbl [5]>
# 2 2 <dbl [5]>
或使用dplyr::group_by
(並保持清潔整齊的有關原則):
t2 %>% group_by(g) %>% your_code
0
split_by
在0.2.3版本已過時 - 見the release notes
現在的功能是pluck
,但你可以通過多個參數 - 從pluck
文檔:
library(purrr)
# pluck() supports integer positions, string names, and functions.
# Using functions, you can easily extend pluck(). Let's create a
# list of data structures:
obj1 <- list("a", list(1, elt = "foobar"))
obj2 <- list("b", list(2, elt = "foobaz"))
x <- list(obj1, obj2)
# And now an accessor for these complex data structures:
my_element <- function(x) x[[2]]$elt
# The accessor can then be passed to pluck:
pluck(x, 1, my_element)
#> [1] "foobar"
pluck(x, 2, my_element)
#> [1] "foobaz"
相關問題
- 1. 在「purrr」包中找不到「contains」函數R
- 2. 在R中找不到rankMatrix函數
- 3. R可找不到包
- 4. 使用purrr的map()函數,結果沒有找到對象
- 5. R - 使用glmnet with purrr/tidyr
- 6. R錯誤:找不到函數「select」
- 7. 找不到函數「.getNamespace」
- 8. R foreach嵌套函數找不到函數使用do.call參數
- 9. 如何在R中找到特定函數的包名?
- 10. 找不到*** in @INC
- 11. 錯誤:在Revolution R中找不到函數「rxGetOption」打開
- 12. 當在r上點擊default.aspx時,找不到'open in browser'選項
- 13. R錯誤:無法找到函數「ggplot」
- 14. R - 在用戶定義的函數中找不到對象
- 15. R studio在我的函數中找不到對象
- 16. R,「tm」包 - 錯誤:語料庫函數未找到
- 17. R基本不可能找到包
- 18. R.NET找不到函數「cor」
- 19. tidyjson找不到函數「spread_all」
- 20. 在java中調用R時找不到某個函數
- 21. Stata的R的「%in%」的等效函數
- 22. 找不到is.wholenumber()函數
- 23. R:從包裝函數傳遞參數到內部函數
- 24. R foreach函數無法找到與souce函數的計數器
- 25. 在動畫包中找不到使用SaveGIF函數的'轉換'
- 26. 如何使用purrr包
- 27. R:錯誤:無法找到函數「tbl_dt」
- 28. R無法找到fct_recode()函數
- 29. JSF in jetty-equinox,在其他包中找不到Bean類
- 30. TypeError:找不到函數1.0
太棒了!非常感謝! – Andy
我更新了以下哈德利的建議,以取代它。 –