Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在R中重复列表中的对象_R_List - Fatal编程技术网

在R中重复列表中的对象

在R中重复列表中的对象,r,list,R,List,我有两个列表文件a和b: a<-list(1,5,8,2,6,4,9,5) b<-list(2,2,3,2,4,1,3,1) 我使用代码:lappy(1:length(a),function(x){rep(a[[x]],b[[x]])},但我想探索其他方法。谢谢你的帮助 您可以使用地图 mapply(function(x,y) rep(x,y), x = a, y = b) [[1]] [1] 1 1 [[2]] [1] 5 5 [[3]] [1] 8 8 8 [[4]] [

我有两个列表文件a和b:

a<-list(1,5,8,2,6,4,9,5)
b<-list(2,2,3,2,4,1,3,1)

我使用代码:
lappy(1:length(a),function(x){rep(a[[x]],b[[x]])}
,但我想探索其他方法。谢谢你的帮助

您可以使用
地图

mapply(function(x,y) rep(x,y), x = a, y = b)
[[1]]
[1] 1 1

[[2]]
[1] 5 5

[[3]]
[1] 8 8 8

[[4]]
[1] 2 2

[[5]]
[1] 6 6 6 6

[[6]]
[1] 4

[[7]]
[1] 9 9 9

[[8]]
[1] 5
Map(rep, a, b)

您可以使用
Map

Map(rep, a, b)

你的意思是
rep(a,b)
?我使用代码如下:lappy(1:length(a),function(x){rep(a[[x]],b[[x]])})rep(a,b)不能工作你的意思是
rep(a,b)
?我使用代码如下:lappy(1:length(a),function(x){rep a[[x]],b[[x]})rep a,b)不能工作