0

My dataframe is like this:


               Habitat DayNight Replicate Mass Peramphithoe_parmerong Ampithoe_caddi Ampithoe_kava
1 Colpomenia_peregrina        D         1  7.9                      0              0             0
2 Colpomenia_peregrina        D         2 11.9                      0              0             1
3 Colpomenia_peregrina        D         3 14.0                      0              0             0
4 Colpomenia_peregrina        D         4  8.7                      0              0             1
5 Colpomenia_peregrina        D         5 12.3                      0              0             0
6 Colpomenia_peregrina        D         6 12.8                      0              1             0
  Ampithoe_ngana Cymadusa_munnu Exampithoe_kutti Plumithoe_quadrimanus
1              0              0                5                     6
2              0              0                2                    13
3              0              6                2                    16
4              0              6                0                    12
5              0              1                0                    37
6              3              4                2                    21


Where the columns [, 5:11] are my species with their respective observations per day/night, replicate and habitat. I want to reshape my df like that:

Species                  Habitat                Obs  DayNight    Replicate 
Peramphithoe_parmerong   Colpomenia_peregrina    0      D           1
Ampithoe_caddi           Colpomenia_peregrina    0      D           2
Ampithoe_kava            Colpomenia_peregrina    0      D           3
(...)

I tried several ways without success.

  • 2
    `tidyr::pivot_longer(your_data, cols = Peramphithoe_parmerong:Plumithoe_quadrimanus, names_to = "Species", values_to = "Obs")` should work. – Gregor Thomas Jun 07 '21 at 15:35

0 Answers0