The following dataframe (dput see below) contains about 500 surface reflection observations from different points accross a time-series.
- Each point belongs to a specific transect (either transsect 1 or 2)
- each transect belongs to an arrangement out of two transsects, called spot (either spot 1 or 2, note: the dput contains only spot 1 because of size restrictions)
- each spot belongs to a site (either site A or B)
From each transsect I filtered the out that 3 points that were mapped most frequently as a given class (in this case WW) in a preceding step and ranked each point by the number of observations.
So far just for understanding the df.
Now, I'd like to filter only those observations for which
- at one date and
- at one transect of same spot and site
all 3 ranks are existing, as e.g. for transect A-1-1 at 20190531 (rows 7 to 9 in the example).
I would like to use dplyr
, but I am quite new to, as generally to R. I did my first experiences with dplyr, but at this point I was struggling for now.
Could anybody help me please?
dput(aaa)
structure(list(Site_ID = c("A", "A", "A", "A", "A", "A", "A",
"A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A",
"A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A",
"A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A",
"A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A",
"A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A",
"A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A",
"A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A",
"A", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B",
"B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B",
"B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B",
"B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B",
"B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B",
"B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B",
"B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B",
"B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B",
"B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B",
"B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B",
"B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B",
"B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B",
"B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B",
"B", "B", "B"), Spot_Nr = c("1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1"), Transkt_Nr = c("1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "2", "2", "2", "2", "2", "2", "2",
"2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2",
"2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2",
"2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2",
"2", "2", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2",
"2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2",
"2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2",
"2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2",
"2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2",
"2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2",
"2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2",
"2", "2", "2", "2"), Point_Nr = c("14", "15", "14", "15", "14",
"15", "14", "15", "13", "14", "15", "14", "15", "14", "15", "15",
"14", "15", "14", "15", "14", "15", "14", "15", "14", "15", "14",
"15", "14", "14", "15", "14", "15", "14", "15", "14", "15", "14",
"15", "14", "15", "14", "15", "14", "15", "13", "14", "13", "14",
"15", "13", "15", "14", "15", "14", "15", "15", "14", "15", "15",
"14", "15", "14", "15", "15", "14", "15", "14", "15", "14", "15",
"15", "15", "14", "15", "14", "15", "15", "14", "15", "15", "14",
"15", "14", "15", "14", "15", "14", "15", "14", "15", "14", "13",
"15", "14", "13", "15", "14", "13", "13", "14", "15", "13", "14",
"15", "13", "14", "15", "13", "14", "13", "14", "15", "13", "14",
"15", "13", "14", "15", "13", "14", "15", "13", "14", "13", "14",
"13", "14", "15", "13", "14", "15", "13", "14", "13", "14", "13",
"14", "13", "14", "13", "14", "13", "14", "13", "14", "13", "14",
"13", "14", "13", "13", "14", "13", "14", "13", "14", "13", "14",
"13", "14", "15", "13", "14", "13", "14", "13", "14", "13", "14",
"13", "14", "13", "14", "15", "13", "14", "15", "13", "14", "12",
"13", "14", "12", "13", "14", "12", "13", "14", "13", "14", "12",
"13", "14", "12", "13", "14", "12", "13", "14", "12", "13", "14",
"13", "14", "12", "13", "14", "12", "13", "14", "12", "13", "14",
"12", "13", "14", "12", "13", "14", "12", "13", "14", "12", "13",
"14", "12", "13", "14", "13", "14", "12", "13", "12", "13", "14",
"12", "13", "13", "12", "13", "14", "13", "13", "14", "12", "13",
"14", "12", "13", "14", "12", "13", "14", "12", "13", "14", "12",
"13", "14", "12", "13", "14", "12", "13", "14", "12", "13", "14",
"12"), nobs = c(24L, 23L, 24L, 23L, 24L, 23L, 24L, 23L, 4L, 24L,
23L, 24L, 23L, 24L, 23L, 23L, 24L, 23L, 24L, 23L, 24L, 23L, 24L,
23L, 24L, 23L, 24L, 23L, 24L, 24L, 23L, 24L, 23L, 24L, 23L, 24L,
23L, 24L, 23L, 24L, 23L, 24L, 23L, 24L, 23L, 4L, 24L, 4L, 24L,
23L, 4L, 26L, 19L, 26L, 19L, 26L, 26L, 19L, 26L, 26L, 19L, 26L,
19L, 26L, 26L, 19L, 26L, 19L, 26L, 19L, 26L, 26L, 26L, 19L, 26L,
19L, 26L, 26L, 19L, 26L, 26L, 19L, 26L, 19L, 26L, 19L, 26L, 19L,
26L, 19L, 26L, 19L, 3L, 26L, 19L, 3L, 26L, 19L, 3L, 34L, 33L,
12L, 34L, 33L, 12L, 34L, 33L, 12L, 34L, 33L, 34L, 33L, 12L, 34L,
33L, 12L, 34L, 33L, 12L, 34L, 33L, 12L, 34L, 33L, 34L, 33L, 34L,
33L, 12L, 34L, 33L, 12L, 34L, 33L, 34L, 33L, 34L, 33L, 34L, 33L,
34L, 33L, 34L, 33L, 34L, 33L, 34L, 33L, 34L, 33L, 34L, 34L, 33L,
34L, 33L, 34L, 33L, 34L, 33L, 34L, 33L, 12L, 34L, 33L, 34L, 33L,
34L, 33L, 34L, 33L, 34L, 33L, 34L, 33L, 12L, 34L, 33L, 12L, 34L,
30L, 28L, 34L, 30L, 28L, 34L, 30L, 28L, 34L, 30L, 34L, 30L, 28L,
34L, 30L, 28L, 34L, 30L, 28L, 34L, 30L, 28L, 34L, 30L, 34L, 30L,
28L, 34L, 30L, 28L, 34L, 30L, 28L, 34L, 30L, 28L, 34L, 30L, 28L,
34L, 30L, 28L, 34L, 30L, 28L, 34L, 30L, 28L, 34L, 30L, 34L, 30L,
28L, 34L, 28L, 34L, 30L, 28L, 34L, 34L, 28L, 34L, 30L, 34L, 34L,
30L, 28L, 34L, 30L, 28L, 34L, 30L, 28L, 34L, 30L, 28L, 34L, 30L,
28L, 34L, 30L, 28L, 34L, 30L, 28L, 34L, 30L, 28L, 34L, 30L, 28L
), rank = c(1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 3L, 1L, 2L, 1L, 2L,
1L, 2L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L,
1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L,
3L, 1L, 3L, 1L, 2L, 3L, 1L, 2L, 1L, 2L, 1L, 1L, 2L, 1L, 1L, 2L,
1L, 2L, 1L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 2L, 1L,
1L, 2L, 1L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 3L,
1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L,
2L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 1L,
2L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 1L, 2L, 1L, 2L, 1L, 2L,
1L, 2L, 1L, 2L, 3L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L,
2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L,
1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 1L, 2L,
3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L,
1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 1L, 2L, 3L, 1L, 3L, 1L, 2L, 3L,
1L, 1L, 3L, 1L, 2L, 1L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L,
2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L,
3L), Tile = c("1008", "1008", "1008", "1008", "1008", "1008",
"1008", "1008", "1008", "1008", "1008", "1008", "1008", "1008",
"1008", "1008", "1008", "1008", "1008", "1008", "1008", "1008",
"1008", "1008", "1008", "1008", "1008", "1008", "1008", "1008",
"1008", "1008", "1008", "1008", "1008", "1008", "1008", "1008",
"1008", "1008", "1008", "1008", "1008", "1008", "1008", "1008",
"1008", "1008", "1008", "1008", "1008", "1008", "1008", "1008",
"1008", "1008", "1008", "1008", "1008", "1008", "1008", "1008",
"1008", "1008", "1008", "1008", "1008", "1008", "1008", "1008",
"1008", "1008", "1008", "1008", "1008", "1008", "1008", "1008",
"1008", "1008", "1008", "1008", "1008", "1008", "1008", "1008",
"1008", "1008", "1008", "1008", "1008", "1008", "1008", "1008",
"1008", "1008", "1008", "1008", "1008", "0909", "0909", "0909",
"0909", "0909", "0909", "0909", "0909", "0909", "0909", "0909",
"0909", "0909", "0909", "0909", "0909", "0909", "0909", "0909",
"0909", "0909", "0909", "0909", "0909", "0909", "0909", "0909",
"0909", "0909", "0909", "0909", "0909", "0909", "0909", "0909",
"0909", "0909", "0909", "0909", "0909", "0909", "0909", "0909",
"0909", "0909", "0909", "0909", "0909", "0909", "0909", "0909",
"0909", "0909", "0909", "0909", "0909", "0909", "0909", "0909",
"0909", "0909", "0909", "0909", "0909", "0909", "0909", "0909",
"0909", "0909", "0909", "0909", "0909", "0909", "0909", "0909",
"0909", "0909", "0909", "0909", "0909", "0909", "0909", "0909",
"0909", "0909", "0909", "0909", "0909", "0909", "0909", "0909",
"0909", "0909", "0909", "0909", "0909", "0909", "0909", "0909",
"0909", "0909", "0909", "0909", "0909", "0909", "0909", "0909",
"0909", "0909", "0909", "0909", "0909", "0909", "0909", "0909",
"0909", "0909", "0909", "0909", "0909", "0909", "0909", "0909",
"0909", "0909", "0909", "0909", "0909", "0909", "0909", "0909",
"0909", "0909", "0909", "0909", "0909", "0909", "0909", "0909",
"0909", "0909", "0909", "0909", "0909", "0909", "0909", "0909",
"0909", "0909", "0909", "0909", "0909", "0909", "0909", "0909",
"0909", "0909", "0909", "0909", "0909", "0909", "0909", "0909",
"0909", "0909", "0909", "0909", "0909", "0909", "0909", "0909"
), Date = c(20190501L, 20190501L, 20190506L, 20190506L, 20190524L,
20190524L, 20190531L, 20190531L, 20190531L, 20190603L, 20190603L,
20190620L, 20190620L, 20190625L, 20190625L, 20190628L, 20190630L,
20190630L, 20190705L, 20190705L, 20190710L, 20190710L, 20190723L,
20190723L, 20190730L, 20190730L, 20190809L, 20190809L, 20190814L,
20190817L, 20190817L, 20190827L, 20190827L, 20190903L, 20190903L,
20190911L, 20190911L, 20190913L, 20190913L, 20190916L, 20190916L,
20190921L, 20190921L, 20191008L, 20191008L, 20191008L, 20191023L,
20191023L, 20191026L, 20191026L, 20191026L, 20190501L, 20190501L,
20190506L, 20190506L, 20190524L, 20190531L, 20190531L, 20190603L,
20190620L, 20190620L, 20190625L, 20190625L, 20190628L, 20190630L,
20190630L, 20190705L, 20190705L, 20190710L, 20190710L, 20190723L,
20190725L, 20190730L, 20190730L, 20190809L, 20190809L, 20190814L,
20190817L, 20190817L, 20190827L, 20190903L, 20190903L, 20190911L,
20190911L, 20190913L, 20190913L, 20190916L, 20190916L, 20190921L,
20190921L, 20191008L, 20191008L, 20191008L, 20191023L, 20191023L,
20191023L, 20191026L, 20191026L, 20191026L, 20180414L, 20180414L,
20180414L, 20180419L, 20180419L, 20180419L, 20180421L, 20180421L,
20180421L, 20180429L, 20180429L, 20180506L, 20180506L, 20180506L,
20180521L, 20180521L, 20180521L, 20180526L, 20180526L, 20180526L,
20180531L, 20180531L, 20180531L, 20180605L, 20180605L, 20180608L,
20180608L, 20180610L, 20180610L, 20180610L, 20180615L, 20180615L,
20180615L, 20180620L, 20180620L, 20180623L, 20180623L, 20180630L,
20180630L, 20180713L, 20180713L, 20180718L, 20180718L, 20180720L,
20180720L, 20180725L, 20180725L, 20180728L, 20180728L, 20180730L,
20180730L, 20180812L, 20180817L, 20180817L, 20180819L, 20180819L,
20180822L, 20180822L, 20180827L, 20180827L, 20180908L, 20180908L,
20180908L, 20180916L, 20180916L, 20180918L, 20180918L, 20180921L,
20180921L, 20180926L, 20180926L, 20180928L, 20180928L, 20181011L,
20181011L, 20181011L, 20181013L, 20181013L, 20181013L, 20180414L,
20180414L, 20180414L, 20180419L, 20180419L, 20180419L, 20180421L,
20180421L, 20180421L, 20180429L, 20180429L, 20180506L, 20180506L,
20180506L, 20180521L, 20180521L, 20180521L, 20180526L, 20180526L,
20180526L, 20180531L, 20180531L, 20180531L, 20180605L, 20180605L,
20180608L, 20180608L, 20180608L, 20180610L, 20180610L, 20180610L,
20180615L, 20180615L, 20180615L, 20180620L, 20180620L, 20180620L,
20180623L, 20180623L, 20180623L, 20180630L, 20180630L, 20180630L,
20180713L, 20180713L, 20180713L, 20180718L, 20180718L, 20180718L,
20180720L, 20180720L, 20180725L, 20180725L, 20180725L, 20180728L,
20180728L, 20180730L, 20180730L, 20180730L, 20180812L, 20180817L,
20180817L, 20180819L, 20180819L, 20180822L, 20180827L, 20180827L,
20180827L, 20180908L, 20180908L, 20180908L, 20180916L, 20180916L,
20180916L, 20180918L, 20180918L, 20180918L, 20180921L, 20180921L,
20180921L, 20180926L, 20180926L, 20180926L, 20180928L, 20180928L,
20180928L, 20181011L, 20181011L, 20181011L, 20181013L, 20181013L,
20181013L), id = c("14", "15", "14", "15", "14", "15", "14",
"15", "13", "14", "15", "14", "15", "14", "15", "15", "14", "15",
"14", "15", "14", "15", "14", "15", "14", "15", "14", "15", "14",
"14", "15", "14", "15", "14", "15", "14", "15", "14", "15", "14",
"15", "14", "15", "14", "15", "13", "14", "13", "14", "15", "13",
"33", "32", "33", "32", "33", "33", "32", "33", "33", "32", "33",
"32", "33", "33", "32", "33", "32", "33", "32", "33", "33", "33",
"32", "33", "32", "33", "33", "32", "33", "33", "32", "33", "32",
"33", "32", "33", "32", "33", "32", "33", "32", "31", "33", "32",
"31", "33", "32", "31", "445", "446", "447", "445", "446", "447",
"445", "446", "447", "445", "446", "445", "446", "447", "445",
"446", "447", "445", "446", "447", "445", "446", "447", "445",
"446", "445", "446", "445", "446", "447", "445", "446", "447",
"445", "446", "445", "446", "445", "446", "445", "446", "445",
"446", "445", "446", "445", "446", "445", "446", "445", "446",
"445", "445", "446", "445", "446", "445", "446", "445", "446",
"445", "446", "447", "445", "446", "445", "446", "445", "446",
"445", "446", "445", "446", "445", "446", "447", "445", "446",
"447", "463", "464", "462", "463", "464", "462", "463", "464",
"462", "463", "464", "463", "464", "462", "463", "464", "462",
"463", "464", "462", "463", "464", "462", "463", "464", "463",
"464", "462", "463", "464", "462", "463", "464", "462", "463",
"464", "462", "463", "464", "462", "463", "464", "462", "463",
"464", "462", "463", "464", "462", "463", "464", "463", "464",
"462", "463", "462", "463", "464", "462", "463", "463", "462",
"463", "464", "463", "463", "464", "462", "463", "464", "462",
"463", "464", "462", "463", "464", "462", "463", "464", "462",
"463", "464", "462", "463", "464", "462", "463", "464", "462",
"463", "464", "462"), Point_ID = c("1014", "1015", "1014", "1015",
"1014", "1015", "1014", "1015", "1013", "1014", "1015", "1014",
"1015", "1014", "1015", "1015", "1014", "1015", "1014", "1015",
"1014", "1015", "1014", "1015", "1014", "1015", "1014", "1015",
"1014", "1014", "1015", "1014", "1015", "1014", "1015", "1014",
"1015", "1014", "1015", "1014", "1015", "1014", "1015", "1014",
"1015", "1013", "1014", "1013", "1014", "1015", "1013", "1033",
"1032", "1033", "1032", "1033", "1033", "1032", "1033", "1033",
"1032", "1033", "1032", "1033", "1033", "1032", "1033", "1032",
"1033", "1032", "1033", "1033", "1033", "1032", "1033", "1032",
"1033", "1033", "1032", "1033", "1033", "1032", "1033", "1032",
"1033", "1032", "1033", "1032", "1033", "1032", "1033", "1032",
"1031", "1033", "1032", "1031", "1033", "1032", "1031", "2013",
"2014", "2015", "2013", "2014", "2015", "2013", "2014", "2015",
"2013", "2014", "2013", "2014", "2015", "2013", "2014", "2015",
"2013", "2014", "2015", "2013", "2014", "2015", "2013", "2014",
"2013", "2014", "2013", "2014", "2015", "2013", "2014", "2015",
"2013", "2014", "2013", "2014", "2013", "2014", "2013", "2014",
"2013", "2014", "2013", "2014", "2013", "2014", "2013", "2014",
"2013", "2014", "2013", "2013", "2014", "2013", "2014", "2013",
"2014", "2013", "2014", "2013", "2014", "2015", "2013", "2014",
"2013", "2014", "2013", "2014", "2013", "2014", "2013", "2014",
"2013", "2014", "2015", "2013", "2014", "2015", "2031", "2032",
"2030", "2031", "2032", "2030", "2031", "2032", "2030", "2031",
"2032", "2031", "2032", "2030", "2031", "2032", "2030", "2031",
"2032", "2030", "2031", "2032", "2030", "2031", "2032", "2031",
"2032", "2030", "2031", "2032", "2030", "2031", "2032", "2030",
"2031", "2032", "2030", "2031", "2032", "2030", "2031", "2032",
"2030", "2031", "2032", "2030", "2031", "2032", "2030", "2031",
"2032", "2031", "2032", "2030", "2031", "2030", "2031", "2032",
"2030", "2031", "2031", "2030", "2031", "2032", "2031", "2031",
"2032", "2030", "2031", "2032", "2030", "2031", "2032", "2030",
"2031", "2032", "2030", "2031", "2032", "2030", "2031", "2032",
"2030", "2031", "2032", "2030", "2031", "2032", "2030", "2031",
"2032", "2030"), RED = c(1719, 1773, 1865, 1906, 1885, 1733,
2221, 2252, 2212, 1936, 1841, 1045, 1015, 1059, 1006, 1299, 1023,
940, 862, 816, 968, 907, 1404, 1252, 1140, 1122, 926, 914, 2025,
1255, 1184, 1824, 1850, 926, 1105, 1081, 1207, 908, 1135, 1156,
1297, 997, 1145, 864, 1421, 1097, 772, 850, 799, 1252, 978, 1745,
1765, 1876, 1901, 1747, 2265, 2205, 1896, 953, 1176, 942, 1206,
1328, 897, 1197, 776, 1007, 846, 1143, 1247, 1102, 1016, 1314,
835, 1115, 2048, 1125, 1467, 1797, 964, 1055, 1088, 1204, 975,
1005, 1191, 1268, 988, 1112, 1174, 870, 1341, 1158, 711, 1034,
1028, 794, 1214, 2484, 2503, 2558, 2130, 2139, 2070, 1876, 1875,
1819, 1686, 1661, 1302, 1255, 1427, 1100, 1026, 1247, 1017, 950,
1259, 1206, 1189, 1348, 1290, 1308, 1288, 1428, 1195, 1232, 1544,
1124, 1081, 1538, 1231, 1241, 1444, 1553, 1297, 1320, 1331, 1391,
1404, 1476, 1365, 1310, 1226, 1201, 1482, 1527, 1249, 1242, 1439,
1260, 1378, 1250, 1200, 1276, 1386, 1226, 1291, 1273, 1268, 1538,
1317, 1391, 1263, 1299, 1188, 1375, 1128, 1222, 1057, 1151, 1194,
1203, 1333, 1278, 1159, 1321, 2507, 2522, 2474, 2137, 2104, 2105,
1860, 1841, 1824, 1644, 1679, 1228, 1250, 1285, 1014, 1025, 1133,
936, 963, 1046, 1148, 1240, 1305, 1246, 1347, 1302, 1467, 1233,
1160, 1291, 1241, 1079, 1136, 1140, 1144, 1314, 1281, 1470, 1665,
1441, 1210, 1397, 1309, 1341, 1511, 1347, 1478, 1598, 1364, 1265,
1367, 1181, 1251, 1213, 1508, 1435, 1149, 1319, 1256, 1402, 1255,
1232, 1094, 1279, 1182, 1213, 1384, 1320, 1196, 1292, 1220, 1250,
1392, 1173, 1098, 1315, 1213, 1090, 1375, 1056, 1038, 1278, 980,
921, 1145, 992, 1137, 1222, 1122, 1127, 1175, 1240), SWIR1 = c(775,
1026, 737, 1111, 1421, 1328, 730, 671, 970, 1375, 1012, 1276,
1108, 1167, 1059, 1239, 1236, 1069, 986, 910, 1128, 961, 1443,
1209, 1387, 1218, 1076, 868, 945, 1201, 1336, 1217, 1228, 1096,
1178, 1097, 1087, 1070, 1057, 1195, 1324, 1157, 1211, 978, 1378,
1132, 1003, 766, 1044, 1127, 904, 1074, 921, 1082, 761, 1357,
591, 808, 982, 970, 1330, 994, 1221, 1191, 947, 1478, 778, 1012,
944, 1401, 1220, 1230, 1109, 1469, 930, 1323, 1171, 1293, 1426,
1116, 1012, 1110, 1025, 1203, 905, 1133, 1147, 1196, 1145, 1324,
1243, 995, 1423, 1041, 994, 922, 1102, 1094, 1111, 557, 722,
729, 203, 207, 220, 221, 189, 155, 926, 847, 588, 570, 614, 675,
363, 775, 664, 640, 737, 835, 826, 1017, 1075, 1040, 688, 933,
941, 753, 1180, 760, 748, 1068, 910, 863, 930, 1116, 1006, 970,
937, 1010, 1009, 1046, 1032, 1037, 975, 938, 1034, 1248, 1007,
969, 1193, 1021, 1251, 1096, 1025, 1136, 1333, 717, 753, 891,
782, 1134, 916, 1036, 1089, 1041, 902, 998, 923, 1007, 840, 845,
926, 837, 1113, 1006, 935, 1181, 677, 828, 467, 196, 189, 213,
150, 147, 167, 803, 802, 410, 460, 481, 475, 328, 572, 476, 571,
635, 707, 792, 963, 901, 970, 628, 948, 865, 635, 760, 877, 562,
655, 854, 684, 839, 957, 824, 1108, 1040, 857, 1044, 1059, 722,
971, 936, 963, 1136, 1109, 862, 1008, 901, 1035, 1229, 907, 1064,
836, 1000, 1087, 1049, 1070, 1023, 909, 1128, 948, 577, 674,
608, 630, 830, 785, 809, 980, 1007, 794, 996, 973, 787, 1187,
860, 796, 968, 901, 616, 788, 885, 806, 867, 932, 823, 909, 1000
), PdKeyT = c(54L, 54L, 53L, 53L, 40L, 40L, 60L, 60L, 60L, 43L,
43L, 20L, 20L, 15L, 15L, 15L, 13L, 13L, 15L, 15L, 13L, 13L, 9L,
9L, 9L, 9L, 7L, 7L, 9L, 6L, 6L, 8L, 8L, 6L, 6L, 12L, 12L, 9L,
9L, 4L, 4L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 2L, 2L, 2L, 54L, 54L,
53L, 53L, 40L, 60L, 60L, 43L, 20L, 20L, 15L, 15L, 15L, 13L, 13L,
15L, 15L, 13L, 13L, 9L, 10L, 9L, 9L, 7L, 7L, 9L, 6L, 6L, 8L,
6L, 6L, 12L, 12L, 9L, 9L, 4L, 4L, 2L, 2L, 2L, 2L, 2L, 3L, 3L,
3L, 2L, 2L, 2L, 109L, 109L, 109L, 98L, 98L, 98L, 80L, 80L, 80L,
37L, 37L, 46L, 46L, 46L, 54L, 54L, 54L, 36L, 36L, 36L, 26L, 26L,
26L, 32L, 32L, 27L, 27L, 20L, 20L, 20L, 34L, 34L, 34L, 23L, 23L,
5L, 5L, 5L, 5L, 9L, 9L, 5L, 5L, 24L, 24L, 2L, 2L, 7L, 7L, 7L,
7L, 5L, 1L, 1L, 0L, 0L, -2L, -2L, 45L, 45L, 5L, 5L, 5L, -3L,
-3L, 5L, 5L, -2L, -2L, 7L, 7L, 7L, 7L, 18L, 18L, 18L, 12L, 12L,
12L, 109L, 109L, 109L, 98L, 98L, 98L, 80L, 80L, 80L, 37L, 37L,
46L, 46L, 46L, 54L, 54L, 54L, 36L, 36L, 36L, 26L, 26L, 26L, 32L,
32L, 27L, 27L, 27L, 20L, 20L, 20L, 34L, 34L, 34L, 23L, 23L, 23L,
5L, 5L, 5L, 5L, 5L, 5L, 9L, 9L, 9L, 5L, 5L, 5L, 24L, 24L, 2L,
2L, 2L, 7L, 7L, 7L, 7L, 7L, 5L, 1L, 1L, 0L, 0L, -2L, 45L, 45L,
45L, 5L, 5L, 5L, -3L, -3L, -3L, 5L, 5L, 5L, -2L, -2L, -2L, 7L,
7L, 7L, 7L, 7L, 7L, 18L, 18L, 18L, 12L, 12L, 12L)), row.names = c(NA,
-270L), class = "data.frame")
CodePudding user response:
I think this is what you want - we group by (look at unique combinations of) Site, Spot, Transect, and Date, and then keep the whole group if ranks 1:3 are all present, and otherwise discard the whole group.
df %>%
group_by(Site_ID, Spot_Nr, Transkt_Nr, Date) %>%
filter(all(1:3 %in% rank))
# # A tibble: 132 × 13
# # Groups: Site_ID, Spot_Nr, Transkt_Nr, Date [44]
# Site_ID Spot_Nr Transkt_Nr Point_Nr nobs rank Tile Date id Point_ID RED SWIR1 PdKeyT
# <chr> <chr> <chr> <chr> <int> <int> <chr> <int> <chr> <chr> <dbl> <dbl> <int>
# 1 A 1 1 14 24 1 1008 20190531 14 1014 2221 730 60
# 2 A 1 1 15 23 2 1008 20190531 15 1015 2252 671 60
# 3 A 1 1 13 4 3 1008 20190531 13 1013 2212 970 60
# 4 A 1 1 14 24 1 1008 20191008 14 1014 864 978 2
# 5 A 1 1 15 23 2 1008 20191008 15 1015 1421 1378 2
# 6 A 1 1 13 4 3 1008 20191008 13 1013 1097 1132 2
# 7 A 1 1 14 24 1 1008 20191026 14 1014 799 1044 2
# 8 A 1 1 15 23 2 1008 20191026 15 1015 1252 1127 2
# 9 A 1 1 13 4 3 1008 20191026 13 1013 978 904 2
#10 A 1 2 15 26 1 1008 20191008 33 1033 1174 1243 2
# # … with 122 more rows
It's hard to know how you might want to generalize this. What I've show is good to check that all of a particular set of rank values are present. You could alternately do a test like n_distinct(rank) >= 3)
if you wanted to keep a group if it had at least 3 distinct ranks.