babesz babesz - 1 year ago 73
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?

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download