I am reading an Excel file which has several variables. I want to keep my first row as the header. I used set_names as below which works. But when I try to remove the first row using slice, it throws an error (Error: Can't bind data because all arguments must be named). Is there a better way to remove first row to avoid this issue?
df <- df%>%
set_names(df[1, ])
You shouldn't need to use set_names(). Most Excel file parsers (such as those provided by the readxl package) contain options to convert the first row into variable names.
Also, can you explain why you are trying to remove the variable names once you've set them?
Thanks @siddharthprabhu! I am yet to figure out how this can be done. But I am trying to do this because while reading this excel sheet using readxl, the variable names are randomly selected by the system such as #, ...3, ...4 as the variable names. The real names are in my first row. I can easily set this in actual excel file. But I would like to know how this can be performed using tidyverse.