I have a dataset containing 120 observations of 6 variables. Five variables are factors, 1 variable is my target variable. I need to write a function that will creates a matrix (for each factor) which contains each level of the factor as columns, and the maximum value of the target variable as first row, and the minimum value of the target variable as the second row.
I know how to create a matrix, however I am lost when I need to make it through a function. Is there someone who can help?
Here is a simple example of what I want to reach with a fictive easy dataset. Example
As you can see, for each level of the factor (on the picture factor 1), I want to indicate the highest value of the target, and the lowest value of the target.