Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Renumbering rows after ordering in R programme

Tags:

I have ordered a set of rows to get this:

2   1983  TRI-COUNTY  TRAUTH         0.1495 0.1395     NA      452 0.0764      4      0  06/02/83 4   1983  TRI-COUNTY  TRAUTH         0.1193 0.1113     NA       32 0.0764      4      2  07/20/83 14  1983  TRI-COUNTY  TRAUTH         0.1064 0.1064     NA       26 0.0763      6      2  08/03/83 17  1983  TRI-COUNTY  TRAUTH         0.1110 0.1010 0.1010      176 0.0763      7      4  08/08/83 24  1983  TRI-COUNTY  TRAUTH         0.1293 0.1215     NA      452 0.0763      4      0  09/12/83 41  1984  TRI-COUNTY  TRAUTH         0.1325 0.1225     NA      452 0.0740      4      0  06/20/84 45  1984  TRI-COUNTY  TRAUTH         0.1425 0.1325     NA       32 0.0741      4      2  07/17/84 47  1984  TRI-COUNTY  TRAUTH         0.1395 0.1395 0.1250       91 0.0741     14     11  07/16/84 

But I want to renumber these such that its 1,2,3,4,etc...

Can someone please help?

like image 653
user1684750 Avatar asked Sep 20 '12 03:09

user1684750


2 Answers

Are you just looking for something like this?:

row.names(datasetname) <- 1:nrow(datasetname) 

Alternatively, if the first column in your example data is a variable (say V1) in a dataframe and not the row.names, this will work:

datasetname$V1 <- 1:nrow(datasetname) 
like image 65
thelatemail Avatar answered Nov 09 '22 15:11

thelatemail


This is the easiest way to do it:

rownames(dataset) = NULL 
like image 35
Josh Levy Avatar answered Nov 09 '22 16:11

Josh Levy