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


col1 <- c(1, 2, 3) col2 <- c(4, 5, 6) col3 <- c(7, 8, 9) 
  • on 1 hand data.frame(col1, col2, col3)

gives

  col1 col2 col3 1    1    4    7 2    2    5    8 3    3    6    9 
  • on other hand paste0("col", 1:3, collapse=", ")

gives

[1] "col1, col2, col3" 
  • question: possible construct data frame using data.frame(paste0("col", 1:3, collapse=", "))?

if have string have objects pasted together, can use strsplit split string , values mget. return list output. wrap data.frame convert 'data.frame`

data.frame(mget(strsplit(str1, ', ')[[1]]))  

data

str1 <- paste0("col", 1:3, collapse=", ") 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -