Reputation: 121
Is there a way to keep the indexes from 1 to N after turning my variable Moy upside down for example my df looks like this;
df <- df[order(df[,1], decreasing= FALSE),]
Moy
10 1.5
7 2.3
5 6.6
4 1.5
1 1.7
0 0.5
And my indexes should look like:(ordered)
Moy
0 1.5
1 2.3
2 6.6
3 1.5
4 1.7
5 0.5
I used order
function but it works only for variables and i can't manipulate the indexes.
Thanks in advance.
Upvotes: 0
Views: 74
Reputation: 57697
If you mean the row names, you can just set them to be sequential: row.names(df) <- seq_len(nrow(df)) - 1
Just wondering, is there a reason why your rows are numbered starting from zero?
Upvotes: 2