So say I have a dataframe like this:
variable1 variable2 variable3
2 0.58955148 0.56320222 0.98544012
3 0.33730801 0.65952594 2.27159478
4 0.99988849 2.55988180 0.34683483
5 1.47543636 0.43682811 0.71149259
And I want a function like this:
filter <- function(dataframe, threshold){}
Where applied could look like this:
filter(dataframe, c(1, 1, 1)
Then I return a new frame where it counts the amount of variables that exceeds the given threshold, like this:
Variable NbrOfExeeding MeanOfCorrect
1 variable1 1 Mean
2 variable2 1 Mean
3 variable3 1 Mean
So the nbr of datapoints exceeding the threshold, and the mean of the rest.
I'm not sure where to start on this. I sort of know what to do but don't know which functions to use. Loop through variable1 and count amount > than threshold. Same for 2 and 3. Get the mean of variable1 omitting number > than threshold. Same for 2 and 3. Get in dataframe. But again, how exactly?