babesz babesz - 9 months ago 45
R Question

How to recount rows in the first column?

I have a data frame where I want to drop some rows, and I've found a fairly elegant way to do this:


however, when I call the data with the head() function, I notice that in the 1st column the rows start from 3,4,5, etc

I also notice that if I export my data into csv and import it again, there is the old column (starting from 3) and a new one appears as well (starting from 1,2,3) which I find redundant.

Is there any way I can tell R to recount the rows of the old column before saving it?


Summarizing the answers given by Vandenman and Rich Scriven:


rownames(Df2) = 1:nrow(Df2) 
row.names(Df2) = 1:nrow(Df2)


rownames(Df2) <- NULL
row.names(Df2) <- NULL


Df2 <- data.frame(Df2, row.names = NULL)
Df2 <-, row.names = NULL)

will do the job