Variable as a column name in data frame

前端 未结 3 1722
无人共我
无人共我 2021-02-06 23:07

Is there any way to use string stored in variable as a column name in a new data frame? The expected result should be:

col.name <- \'col1\'
df <- data.fram         


        
3条回答
  •  生来不讨喜
    2021-02-06 23:32

    I don't recommend you do this, but:

    col.name <- 'col1'
    eval(parse(text=paste0('data.frame(', col.name, '=1:4)')))
    

提交回复
热议问题