R: constructing a data frame with many columns using paste()

前端 未结 2 969
萌比男神i
萌比男神i 2021-01-28 02:02
col1 <- c(1, 2, 3)
col2 <- c(4, 5, 6)
col3 <- c(7, 8, 9)
  • On the one hand data.frame(col1, col2, col3)

gives<

2条回答
  •  一生所求
    2021-01-28 02:12

    You may want to use mget

    do.call(cbind, mget(paste0("col", 1:3)))
    

    Where the paste0 generates the variable names, mget gets the associated values, and cbind puts them together into a data frame.

提交回复
热议问题