Convert first row as column name in a list of dataframes, then delete first row

前端 未结 1 895
礼貌的吻别
礼貌的吻别 2021-01-16 02:05

I am relatively new to R, and am facing an issue trying to convert the first row of a list of dataframe into the column name.

I have a dataframe of 120 rows, the dp

相关标签:
1条回答
  • 2021-01-16 02:47

    Your function inside lapply returns x[1, ] only. You have to return the whole data frame instead. Use this command:

    lapply(cmonlist, function(x) "names<-"(x, x[1, ]))
    

    If you also want to remove the first row of each data frame, use this:

    lapply(cmonlist, function(x) tail("names<-"(x, x[1, ]), -1))
    
    0 讨论(0)
提交回复
热议问题