I am trying to split my data into lists based on the combinations of some column and apply a normalisation function based on the min and max of the data from the different combinations.
If I am using the iris data set then I would like to have the following combinations.
setosa & versicolor versicolor & virginica setosa & virginica
Where I will apply the following function:
normaliseData <-function(m, min_m, max_m){
(m - min(m)) / (max(m) - min(m))
}
So the first data frame will use the values from the min and max between setosa & versicolor. I am only interested in applying the normalisation to a single column in the data frame i.e.
iris %>%
select(Petal.Width, Species)
I can get the min and max for one combination using:
iris %>%
filter(Species == "setosa" | Species == "versicolor") %>%
summarise(
min_m = min(Petal.Width),
max_m = max(Petal.Width)
)
My idea is to first create a list for each of the combinations of the data. Then map the normalisation function over each of the lists. I have looked at the combn function but cannot get it to split the data.
EDIT: I would ignore this part below Running:
expand.grid(colnames(iris[,1:4]), colnames(iris[,1:4])) %>%
filter(!Var1 == Var2)
Gets me:
Var1 Var2
1 Sepal.Width Sepal.Length
2 Petal.Length Sepal.Length
3 Petal.Width Sepal.Length
4 Sepal.Length Sepal.Width
5 Petal.Length Sepal.Width
6 Petal.Width Sepal.Width
7 Sepal.Length Petal.Length
8 Sepal.Width Petal.Length
9 Petal.Width Petal.Length
10 Sepal.Length Petal.Width
11 Sepal.Width Petal.Width
12 Petal.Length Petal.Width
But this does not give me unique combinations as such, since "Sepal.Width & Sepal.Length" is the same as "Sepal.Length & Sepal.Width".