cbind a dynamic column name from a string in R

后端 未结 4 2208
-上瘾入骨i
-上瘾入骨i 2021-01-19 03:35

I want to cbind a column to the data frame with the column name dynamically assigned from a string

y_attribute = \"Survived\"
cbind(test_data, y_attribute =         


        
4条回答
  •  长发绾君心
    2021-01-19 04:12

    Not proud of this but I usually will do somethingl like this:

    dyn.col <- "XYZ"
    cbind(test.data, UNIQUE_NAMEXXX=NA)
    colnames(test.data)[colnames(test.data == 'UNIQUE_NAMEXXX')] <- dyn.col
    

提交回复
热议问题