小编Ann*_*son的帖子

R是否等效于Python的'*'?

在python中,您可以执行以下操作:

val = [1, 2, 3]

def f(a, b, c):
    return(a+b+c)

f(*val)

>>>6
Run Code Online (Sandbox Code Playgroud)

但是,是否有一个R等效于将列表/向量传递给函数并将其解压缩为函数的参数?

val <- c(1, 2, 3)
f <- function(a, 
              b, 
              c) {
     a+b+c
     }
#f(*val)
Run Code Online (Sandbox Code Playgroud)

r

3
推荐指数
1
解决办法
78
查看次数

Itertools groupby: group list of lists by first two values of sublists

I have a list of lists like this:

data = [['a', 'b', 2000, 100], ['a', 'b', 4000, 500], ['c', 'd', 500, 8000], ['c', 'd', 60, 8000], ['c', 'd', 70, 1000], ['a', 'd', 2000, 100], ['a', 'd', 1000, 100]]
Run Code Online (Sandbox Code Playgroud)

and I want to group them together if they have the same first two values. Output would be:

data = [(['a', 'b', 2000, 100], ['a', 'b', 4000, 500]), (['c', 'd', 500, 8000], ['c', 'd', 60, 8000], ['c', 'd', 70, 1000]), (['a', 'd', …
Run Code Online (Sandbox Code Playgroud)

python performance group-by python-itertools

0
推荐指数
1
解决办法
61
查看次数

标签 统计

group-by ×1

performance ×1

python ×1

python-itertools ×1

r ×1