Change rows index dataframe R

It seems like you want to remove your row names?

df <- data.frame("Colours" = c("Red", "Red", "Green", "Yellow"), 
                 "Number" = c(1,2,3,6))
rownames(df) <- c(1,2,3,6)
df
  Colours Number
1     Red      1
2     Red      2
3   Green      3
6  Yellow      6

Setting rownames as NULL, we will remove the row names and they will be called by just row number now.

rownames(df) <- NULL
df
  Colours Number
1     Red      1
2     Red      2
3   Green      3
4  Yellow      6

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top