how to combine vectors with different length within a list in R?

后端 未结 3 2089
故里飘歌
故里飘歌 2021-02-09 14:58

I have a problem when combining the following vectors included in the list:

x <- list(as.numeric(c(1,4)),as.numeric(c(3,19,11)))
names (x[[1]]) <- c(\"spec         


        
3条回答
  •  不要未来只要你来
    2021-02-09 15:47

    It looks like you're actually trying to do a merge. As such, merge will work. You just have to tell it to merge on the names, and to keep all rows.

    do.call(merge, c(x, by=0, all=TRUE))   # by=0 and by="row.names" are the same
    

    (This will create a data frame rather than a matrix, but for most purposes that shouldn't be an issue.)

提交回复
热议问题