I have a list L
of dataframes where each dataframe consists of the variable Var
and one observation that consists of different numbers. Each number in each observation belongs to the set {1,2,3,4,5,11,12,13,14,15}
. L
could, as an example, look like:
> L
[[1]]
Var
1 "3", "11", "1", "15",
[[2]]
Var
1 "5", 13", "3", "12",
[[3]]
Var
1 "4", "1", "2", "5",
The problem I am trying to solve is the following. I want to know if there is a positive number x = {1,2,3,4,5}
such that when added to each number in a given observation, that observation becomes equivalent to another. For example, consider the first 2 elements of L
and let x=2
, then, adding x
to the first element of L
yields:
> L[[1]]
Var
1 "5", "13", "3", "17",
The number 17 does not meet the conditions of the set defined above. I want the following constraints to apply on x
. Let y
denote a number in an obs. in a dataframe of L
:
if y + x > 15 then subtract 5
if 5 < y + x < 11 then subtract 5
The same example with these constraints would yield:
> L[[1]]
Var
1 "5", "13", "3", "12",
And L[[1]]
would become equivalent to L[[2]]
. In my world, L[[1]]
and L[[2]]
share the same pattern. What I want to do is to match elements of L
based on equivalent (in the sense described above) patterns and sort the groups according to "the number of members". So in the example here I'd like to detect that L[[1]]
and L[[2]]
are in one group and that this is the group with most members, followed by the next group, that in this example only consists of L[[3]]
. I am very new to R and any guidance would be appreciated!