Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.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
在do.call中使用rbind时如何避免重命名行?_R_Rbind_Do.call - Fatal编程技术网

在do.call中使用rbind时如何避免重命名行?

在do.call中使用rbind时如何避免重命名行?,r,rbind,do.call,R,Rbind,Do.call,我试图绑定列表中元素的一些子元素 清单OC如下 > library(quantmod) > OC <- getOptionChain('AAPL', NULL) > str(OC) List of 9 $ Feb 2013:List of 3 ..$ calls :'data.frame': 35 obs. of 7 variables: .. ..$ Strike: num [1:35] 380 390 400 410 420 430 440 445 4

我试图绑定列表中元素的一些子元素

清单
OC
如下

> library(quantmod)
> OC <- getOptionChain('AAPL', NULL)

> str(OC)
List of 9
 $ Feb 2013:List of 3
  ..$ calls :'data.frame':  35 obs. of  7 variables:
  .. ..$ Strike: num [1:35] 380 390 400 410 420 430 440 445 450 455 ...
  .. ..$ Last  : num [1:35] 89.9 86 60 49.5 39.8 ...
  .. ..$ Chg   : num [1:35] 0 0 -0.4 -4.4 -0.7 -1.9 -0.55 -0.7 -0.95 -1 ...
  .. ..$ Bid   : num [1:35] 79.5 69.8 59.8 49.8 39.6 ...
  .. ..$ Ask   : num [1:35] 80.2 70.2 60.2 50.2 40.2 ...
  .. ..$ Vol   : num [1:35] 1 1 48 11 61 ...
  .. ..$ OI    : num [1:35] 2 2 55 29 41 ...
  ..$ puts  :'data.frame':  40 obs. of  7 variables:
  .. ..$ Strike: num [1:40] 380 385 390 395 400 405 410 415 420 425 ...
  .. ..$ Last  : num [1:40] 0.01 0.05 0.07 0.08 0.03 0.04 0.02 0.04 0.06 0.06 ...
  .. ..$ Chg   : num [1:40] -0.03 0 0 0 -0.08 -0.06 -0.1 -0.08 -0.11 -0.17 ...
  .. ..$ Bid   : num [1:40] NA 0.01 NA NA 0.02 0.01 0.01 0.04 0.05 0.06 ...
  .. ..$ Ask   : num [1:40] 0.01 0.02 0.03 0.03 0.03 0.04 0.06 0.06 0.07 0.09 ...
  .. ..$ Vol   : num [1:40] 15 122 1 117 186 ...
  .. ..$ OI    : num [1:40] 120 99 638 95 1319 ...
  ..$ symbol: chr "AAPL"
 $ Mar 2013:List of 3
  ..$ calls :'data.frame':  221 obs. of  7 variables:
  .. ..$ Strike: num [1:221] 255 265 
##.............truncated manually for post...........
但是,每个行名前面都有其父元素的名称。有没有办法避免这种情况?

我尝试为
rbind
设置
deparse.level=0
,但结果不是我想要的

> allputs <- do.call('rbind', list(lapply(OC, FUN = function(x) x$puts), deparse.level=0))
> head(allputs)
     Feb 2013 Mar 2013 Apr 2013 May 2013 Jun 2013 Jul 2013 Oct 2013 Jan 2014 Jan 2015
[1,] List,7   List,7   List,7   List,7   List,7   List,7   List,7   List,7   List,7  

> str(allputs[1])
List of 1
 $ :'data.frame':   40 obs. of  7 variables:
  ..$ Strike: num [1:40] 380 385 390 395 400 405 410 415 420 425 ...
  ..$ Last  : num [1:40] 0.01 0.05 0.07 0.08 0.03 0.04 0.02 0.04 0.06 0.06 ...
  ..$ Chg   : num [1:40] -0.03 0 0 0 -0.08 -0.06 -0.1 -0.08 -0.11 -0.17 ...
  ..$ Bid   : num [1:40] NA 0.01 NA NA 0.02 0.01 0.01 0.04 0.05 0.06 ...
  ..$ Ask   : num [1:40] 0.01 0.02 0.03 0.03 0.03 0.04 0.06 0.06 0.07 0.09 ...
  ..$ Vol   : num [1:40] 15 122 1 117 186 ...
  ..$ OI    : num [1:40] 120 99 638 95 1319 ...
> str(allputs[2])
List of 1
 $ :'data.frame':   207 obs. of  7 variables:
  ..$ Strike: num [1:207] 255 260 265 270 275 280 285 290 295 300 ...
  ..$ Last  : num [1:207] 0.08 0.03 0.06 0.01 0.03 0.1 0.02 0.02 0.05 0.02 ...
  ..$ Chg   : num [1:207] 0 0.02 0 0 0 0 0 0 0 0 ...
  ..$ Bid   : num [1:207] NA NA NA NA NA NA NA NA NA NA ...
  ..$ Ask   : num [1:207] 0.02 0.01 0.02 0.02 0.02 0.02 0.02 0.03 0.03 0.03 ...
  ..$ Vol   : num [1:207] 5 30 5 10 3 6 1 10 5 2 ...
  ..$ OI    : num [1:207] 33 668 541 512 455 ...
>allput头(allput)
2013年2月2013年3月2013年4月2013年5月2013年6月2013年7月2013年10月2014年1月2015年1月
[1,]列表,7列表,7列表,7列表,7列表,7列表,7列表,7列表,7列表,7列表,7列表,7
>str(allput[1])
1人名单
$:'data.frame':40 obs。共有7个变量:
..$Strike:num[1:40]380 385 390 395 400 405 410 415 420 425。。。
..$Last:num[1:40]0.01 0.05 0.07 0.08 0.03 0.04 0.02 0.04 0.06 0.06。。。
..$Chg:num[1:40]-0.03-0.08-0.06-0.1-0.08-0.11-0.17。。。
..$Bid:num[1:40]NA 0.01 NA 0.02 0.01 0.01 0.04 0.05 0.06。。。
..$Ask:num[1:40]0.01 0.02 0.03 0.03 0.03 0.04 0.06 0.06 0.07 0.09。。。
..$Vol:num[1:40]15122171717186。。。
..$OI:num[1:40]12099638951319。。。
>str(allputs[2])
1人名单
$:'data.frame':207 obs。共有7个变量:
..$Strike:num[1:207]255 260 265 270 275 280 285 290 295 300。。。
..$Last:num[1:207]0.08 0.03 0.06 0.01 0.03 0.1 0.02 0.02 0.05 0.02。。。
..$Chg:num[1:207]0.02 0 0 0 0。。。
..$Bid:num[1:207]不,不,不,不。。。
..$Ask:num[1:207]0.02 0.01 0.02 0.02 0.02 0.02 0.02 0.03 0.03。。。
..$Vol:num[1:207]5305103611052。。。
..$OI:num[1:207]33668541512 455。。。

使用
data.table::rbindlist
可以避免
do.call(rbind,…)

这将返回一个
数据表<代码>数据。表
没有行名

它也快得令人目眩

library(data.table)
allputs <- rbindlist(lapply(OC, FUN = function(x) x$puts))
# my eyes, I'm blinded!

这里需要注意的是,
rbindlist
已经期望每个项目都是一个统一的列表、data.frame或data.table
。有没有办法使用
do.call的
args
param来传递
rbind
a
row.names=F
或什么的?@d8anija您可以使用
do.call(rbind,c(yourlist,make.row.names=FALSE))
;参见
?do.call
中的第二个示例:“如果我们已经有了一个列表[…],我们需要
c()
来添加更多的参数”在base R中实现这一点的方法是
unname
传递给
rbind
do.call('rbind',unname(lappy(OC,FUN=function(x)x$put))
library(data.table)
allputs <- rbindlist(lapply(OC, FUN = function(x) x$puts))
# my eyes, I'm blinded!
lputs <- lapply(OC, FUN = function(x) x$puts)


 allputs <- rbindlist(lputs)
 # add the column with rownames
 allputs[,rn := unlist(lapply(lputs, rownames))]
 names(lputs) <- NULL

 do.call('rbind', lputs)