+2 votes
in Programming Languages by (39.4k points)
My input file does not have column names. I want to put column names (header) after reading the file as a DataFrame. How can I add a header to an R DataFrame?

1 Answer

+3 votes
by (281k points)
selected by
Best answer

You can use the names() function to set the header of a DataFrame.

Here is an example:

names(your_dataframe) <- c("col1", "col2", "col3")

The above example adds a header to the DataFrame with 3 columns: "col1", "col2", "col3".

Related questions

+5 votes
1 answer
+4 votes
1 answer
+1 vote
1 answer
+3 votes
1 answer