我有谁列出:
list_a = [['abc', 10],['def', 20],['ghj', 30]]
list_b = [['abc', 40],['def', 50],['ghj', 60],['klm', 70]]
我想通过list.a浏览list.b所以我可以删除备用元素" list.b [3]"并使用列表成员计算:
list_a[0][1] - list_b[0][1] = -30
list_a[1][1] - list_b[1][1] = -30
list_a[2][1] - list_b[2][1] = -30
我到底该怎么做?
答案 0 :(得分:4)
使用#example data of what I want
dat$group <- c(1, 1, 1, 2, 2, 1, 1, 1, 2, 2) #this is the variable I want
dat$seq <- with(dat, ave(as.character(category), category, FUN = seq_along)) #count sequence variable, which is different than what I'm after because it does not repeat within sequential categories
> dat
id time category group seq
1 a 2016-10-24 21:05:00 low 1 1
2 a 2016-10-24 21:10:00 high 1 1
3 a 2016-10-24 21:15:00 high 1 2
4 a 2016-10-24 21:20:00 low 2 2
5 a 2016-10-24 21:25:00 low 2 3
6 b 2016-10-24 21:30:00 low 1 4
7 b 2016-10-24 21:35:00 high 1 3
8 b 2016-10-24 21:40:00 high 1 4
9 b 2016-10-24 21:45:00 low 2 5
10 b 2016-10-24 21:50:00 low 2 6
。它将自动修剪到最短迭代的长度。这是列表理解:
zip