Q
在函數中重複參數
0
A
回答
2
功能rep
似乎做你想做的。
n <- 3 #number of repetitions
x <- list(seq(1,5))
expand.grid(rep(x,n)) #gives a data.frame of 125 rows and 3 columns
x2 <- list(a = seq(1,5), b = seq(6, 10))
expand.grid(rep(x2,n)) #gives a data.frame of 15625 rows and 6 columns
0
0
我認爲,解決原來的問題最簡單的方法是使用rep
嵌套列表。
例如,要展開n次相同的列表,使用rep根據需要多次展開嵌套列表(n
),然後使用展開的列表作爲expand.grid
的唯一參數。
# Example list
l <- list(1, 2, 3)
# Times required
n <- 3
# Expand as many times as needed
m <- rep(list(l), n)
# Expand away
expand.grid(m)
0
如果該函數要在列表的元素(重複地)動作自如(即,列表成員是從所定義的列表本身未連接),以下將是有用的:
l <- list(1:5, "s") # A list with numerics and characters
n <- 3 # number of repetitions
expand.grid(unlist(rep(l, n))) # the result is:
Var1
1 1
2 2
3 3
4 4
5 5
6 s
7 1
8 2
9 3
10 4
11 5
12 s
13 1
14 2
15 3
16 4
17 5
18 s
相關問題
- 1. 函數中的重複參數檢查
- 2. 在函數中重複函數R
- 3. 在Python中重複函數
- 4. 重複參數
- 5. 複雜的函數參數
- 6. itertools.product重複參數
- 7. 重複printf參數
- 8. Powershell函數中的可重複參數(最好鏈接的參數集)
- 9. WP_Query中的重複函數
- 10. 函數參數傳遞和函數重定義在Julia中
- 11. 模塊中的重複函數和更改默認參數
- 12. 如何避免clojure中的重複函數參數?
- 13. 多參數重載函數
- 14. 函數重載和參數
- 15. jQuery函數重複
- 16. 重複php函數
- 17. 重複JS函數
- 18. 在Rest-Assured中重複查詢參數
- 19. AngularJS內NG重複不處理$指數函數參數$父
- 20. 在Mathematica中重複n次函數
- 21. 在javascript中調用重複函數
- 22. 在Javascript中識別重複函數
- 23. 在Excel中重複嵌套函數
- 24. 函數在JavaScript中重複n次
- 25. 在Scheme中重複應用函數?
- 26. 在Permute函數中重複的問題
- 27. 調用函數的Python重複函數
- 28. 抽象函數/避免函數重複
- 29. 函數重複的重置計數器
- 30. 在Python中重複函數內函數3
您是否想要展開原始對象的列表?然後看我的答案,一個更復雜的對象列表可以用@ Qaswed的回答來解決 – NJBurgo