[R] Find the max entry in column 2 - that satisfies a condition given a fixed entry in column 1
Vangelis Litos
Redondo5_447 @end|ng |rom hotm@||@com
Thu Jun 20 11:15:12 CEST 2019
I am using R and I created based on a vector x, a grid (named: plain) - where zero is included. This gives me a 9x2 ``matrix''.
> x_t = cbind(c(1),c(2));
> x = t(x_t);
> plain = expand.grid (sort (unique (c (0, x))), sort (unique (c (0, x))));
My aim is to focus on column 1 and take i.e the first entry (then the second, the third entry etc through a loop) of the unique (c (0, x)) vector (==0) [rows 1, 4 and 7] and find the maximum value (entry) in the second column of the matrix that satisfies a condition.
Let say that the condition is satisfied when at column 2 the value is 2. That is I want row 7 to be selected
Then I want to create a column vector b (9x1) that has zero everywhere apart from row 7.
Can anybody help me with this?
Thank you in advance.
[[alternative HTML version deleted]]
More information about the R-help
mailing list