Rearrange Row Order dataframe

1

I have the respective data.frame in the R:

                   Produto  Classificação Comum Quilo
1            ABACAXI HAVAI       A GRAUDO  3,32   2,2
2            ABACAXI HAVAI        B MEDIO  2,81   1,8
3            ABACAXI HAVAI        C MIUDO  2,21   1,4
4              BANANA MACA              -   4,5     1
5          BANANA PRATA MG              -  3,13     1
6          BANANA PRATA SP              -  2,82     1
7    BANANA NANICA CLIMAT.              -  2,16     1
8               COCO VERDE              -  2,09   2,5
9                 UVA RUBI       ESPECIAL  4,14     1
10            LARANJA LIMA    A (9/12 DZ)  2,46     1
11            LARANJA LIMA   B (13/15 DZ)  2,16     1
12            LARANJA LIMA   C (16/21 DZ)  1,97     1
13            LARANJA PERA    A (9/12 DZ)  2,81     1
14            LARANJA PERA   B (13/15 DZ)  2,62     1
15   MACA ESTRANG. RED DEL  80-163 FRUTOS  5,32     1
16      MACA NACIONAL FUJI 163-180 FRUTOS  5,31     1
17           MAMAO FORMOSA              A  3,12     1
18                MANDIOCA          MEDIA  1,86     1
21  TOMATE ACHATADO-REDOND        EXTRA A   2,1     1
19         BATATA ESCOVADA       ESPECIAL  1,46     1

If I want to change the order of the lines, for example, leaving in that order:

ABACAXI HAVAI   A GRAUDO
ABACAXI HAVAI   B MEDIO
ABACAXI HAVAI   C MIUDO
BANANA MACA -
BANANA PRATA MG -
BANANA PRATA SP -
BANANA NANICA CLIMAT.   -
COCO VERDE  -
LARANJA LIMA    A (9/12 DZ)
LARANJA LIMA    B (13/15 DZ)
LARANJA LIMA    C (16/21 DZ)
LARANJA PERA    A (9/12 DZ)
LARANJA PERA    B (13/15 DZ)
MACA ESTRANG. RED DEL   80-163 FRUTOS
MACA NACIONAL FUJI  163-180 FRUTOS
MAMAO FORMOSA   A
UVA RUBI    ESPECIAL
MANDIOCA    MEDIA
TOMATE ACHATADO-REDOND  EXTRA A
BATATA ESCOVADA ESPECIAL

(in this case only changing the location of the UVA RUBI)

How could I do this?

    
asked by anonymous 09.03.2017 / 22:30

1 answer

1

In your specific case, you are putting line 9 in position 17. So assuming your data.frame is called df , you can simply select the lines in that order:

df_novo <- df[c(1:8, 10:17, 9, 18:nrow(df)), ] # troca linha 9 de posição
    
10.03.2017 / 23:50