[Solved] Exclude column 0 (rownames) column from data frame and csv output


You can drop the rownames of a dataframe by simply setting them to null. They’re null by default (see ?data.frame), but sometimes they get set by various functions:

# Create a sample dataframe with row.names
a_data_frame <- data.frame(letters = c("a", "b", "c"), 
                           numbers = c(1, 2, 3), 
                           row.names = c("Row1", "Row2", "Row3"));
# View it
a_data_frame;
>        letters numbers
>Row1       a       1
>Row2       b       2
>Row3       c       3

# Use rownames() to set them to new value, which is null in this case
rownames(a_data_frame) <- NULL;

# View it again
a_data_frame;
>     letters numbers
>1       a       1
>2       b       2
>3       c       3

Note that NULL rownames show up as an incremental count when printed, but no longer exist in the a_data_frame data frame object, so when handled by another function like write.csv, any rownames that you see are created by the function, not taken from the data frame object itself.

As mentioned by the previous poster (see ?write.csv), you can specify row.names=FALSE in your write.csv command.

solved Exclude column 0 (rownames) column from data frame and csv output