CH00CH00CHARLIE
CH00CH00CHARLIE

Reputation: 55

Having issues with how the order function places data in a data frame

Here is my code I used to generate the data and the order:

cd1 = data_grouped1
cd2 = data_grouped2
smth_ln = lowess(cd1,cd2)
data_frame = data.frame(cd1,cd2)
ordered_data_frame = data_frame[order(data_frame$cd1),]

The problem is with the output of ordered_data_frame:

          cd1        cd2
12   1.318415   8.862540
20   1.519023  13.741513
3    2.573028  11.693841
11   3.563886   5.304126
7    3.724844   1.275584
18   4.328285  18.567782
1    4.341053  16.394396
15   5.881258   5.234056
10   6.644274   4.099856
6    8.945707   2.146440
5   13.626985   4.303261
13  13.634724   1.903644
19  15.960787  18.295842
17  16.178757   1.618921
14  17.131918   5.370007
8   17.659915  14.749284
2   17.667276  19.944927
4   18.117436   1.924418
16  19.360616   4.833260
9   19.419893  16.906275
21  32.000000  32.000000
30  46.721647  47.579620
24  47.037481  58.067666
37  47.041261  49.745445
33  48.340455  56.658117
29  48.550545  52.604374
23  49.261857  46.933329
27  53.141933  50.356975
35  53.758462  47.410978
25  54.520715  63.751819
36  54.928822  57.936303
22  54.984661  57.584271
32  55.168681  54.356549
39  55.644641  48.609097
26  55.715000  52.224896
38  57.922253  62.811781
28  58.841785  51.785899
31  61.467844  61.135294
41  62.695972  45.378379
40  62.931873  49.761754
34  63.693611  64.992095
42  77.000000  77.000000
50  90.609768  97.506675
44  91.020031  90.244383
55  91.137912  96.011707
61  91.397239 108.294665
54  91.889118  99.056465
47  92.737411 106.473752
43  93.466673  98.181285
49  95.869575 104.302920
60  98.656112  94.020177
51 100.751787 109.526907
56 101.063894  94.348411
58 101.414849  93.085549
45 102.129438  94.385133
57 103.216284  91.409923
48 105.242092 102.235231
59 106.450540  93.623984
53 106.742784 109.760631
46 108.038967 100.258215
52 108.553941  92.189376
62 109.632530  93.982546    

I need the leftmost numbers to be sequential so that the data frame can work with a later if statement but I can't find a way to implement that. I want the leftmost numbers to reflect their current order and not the place they were before being ordered.

Upvotes: 1

Views: 30

Answers (2)

Rui Barradas
Rui Barradas

Reputation: 76615

As far as I know, the simplest way is

rownames(ordered_data_frame) <- NULL

This works since row names are mandatory for data frames. So R will use the default ones, 1:nrow(ordered_data_frame).

Upvotes: 2

janos
janos

Reputation: 124724

You can reset the row names with:

rownames(ordered_data_frame) <- rownames(data_frame)

Upvotes: 1

Related Questions