Assign column names to list of dataframes

前端 未结 1 1803
情深已故
情深已故 2020-12-16 20:24

I have a list of dataframes, whose columns have names.

If I want to change the names of the dataframes within the list (rather than the names of the parent list), I

相关标签:
1条回答
  • 2020-12-16 21:01

    You can use setNames...

    lapply( y , setNames , nm = c('Op', 'Hi', 'Lo', 'Clo') )
    #[[1]]
    #                 Op       Hi       Lo      Clo
    #2007-01-02 50.03978 50.11778 49.95041 50.11778
    #2007-01-03 50.23050 50.42188 50.23050 50.39767
    #2007-01-04 50.42096 50.42096 50.26414 50.33236
    #       ...      ...      ...      ...      ...
    

    Quoting directly from the help page:

    This is a convenience function that sets the names on an object and returns the object. It is most useful at the end of a function definition where one is creating the object to be returned and would prefer not to store it under a name just so the names can be assigned.

    0 讨论(0)
提交回复
热议问题