How to avoid renaming of rows when using rbind inside do.call?

后端 未结 1 1015
别跟我提以往
别跟我提以往 2021-02-20 13:00

I am trying to bind some sub elements of the elements from the list

The list OC is as follows

> library(quantmod)
> OC <- getOptio         


        
相关标签:
1条回答
  • 2021-02-20 13:38

    You can avoid do.call(rbind,...) by using data.table::rbindlist.

    This will return a data.table. data.tables don't have rownames.

    It is also blindingly fast!

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

    If you want to include the original rownames as a column then

    lputs <- lapply(OC, FUN = function(x) x$puts)
    
    
     allputs <- rbindlist(lputs)
     # add the column with rownames
     allputs[,rn := unlist(lapply(lputs, rownames))]
    

    If you don't want to move to data.tables, then you could set the parent names to NULL

     names(lputs) <- NULL
    
     do.call('rbind', lputs)
    
    0 讨论(0)
提交回复
热议问题