Insert i th vector number into data frame column name - R

前端 未结 1 867
梦如初夏
梦如初夏 2021-01-22 20:05

This is likely a quick fix! I am trying to place the ith position of my vector into my data frame column name. I am trying to use paste0 to enter the ith number.



        
相关标签:
1条回答
  • 2021-01-22 20:25

    You should treat the dataframe as a list. So avoid the "$" operator and instead use [[]].

    so:

    spx.sma <- df[[paste0("close.sma.n", sma[i])]]
    
    0 讨论(0)
提交回复
热议问题