Conditional formatting formula QUERY() inside UNIQUE() - google-sheets

I want to conditionally format rows that have values in their G or H column that are unique among rows with the same B and C column values. I tried writing a query inside of the unique function that selects rows where B and C equal the previous row. Here is my attempt:
= AND(
$C3 = $C2, $B3 = $B2, OR(
$G3 = UNIQUE(
QUERY(
A2:J417, "select G where B = B - 1 AND C = C - 1"
)
),
$H3 = UNIQUE(
QUERY(
A2:J417, "select H where B = B - 1 AND C = C - 1"
)
)
)
)
Could someone help me with this?
Sample data:
A B C D E F G H
52 120 min Fe (2+) 3 0.229 0.496 10x 16x
53 120 min Fe (2+) 4 0.240 0.507 10x 16x
54 120 min Fe (2+) 5 0.226 0.499 10x 16x
55 120 min Fe (2+) 6 0.228 0.486 10x 16x
56 120 min Fe (2+) 7 0.249 0.465 10x 20x
57 120 min Fe (3+) 1 0.223 0.429 5x 10x
58 120 min Fe (3+) 2 0.236 0.468 5x 10x
59 120 min Fe (3+) 3 0.223 0.418 5x 10x
60 120 min Fe (3+) 4 0.229 0.446 5x 10x
Row 5 would be highlighted because it is 120 min, Fe (2+) but has a different concentration for column H.

try:
=INDEX(
COUNTIFS($B$1:$B&$C$1:$C&$G$1:$G&$H$1:$H, $B1&$C1&$G1&$H1, ROW($B$1:$B), ">="&ROW($B1))=
COUNTIFS($B$1:$B&$C$1:$C&$G$1:$G&$H$1:$H, $B1&$C1&$G1&$H1, ROW($B$1:$B), "<="&ROW($B1)))

Related

How to take all values from a single cell

I have the following data
X f1 f2 f3
1 20 20/5/2 3
2 0 10/5/0 7
3 15 20/2/1 3
4 30 80/0/9 3
I want to make SUM() of all values in f2 column but it gives me an error because of the /.
How can I take each value, separately?
Plus, how to get each relative percentage of each cell in f2? For example, the first cell of f2 would be 74,07 / 18,52 / 7,41 taken from doing (20/27 - 5/27- 2/27)
use:
=INDEX(SUM(IFERROR(SPLIT(F1:F; "/"); 0)*1))
update:
=ARRAYFORMULA(IF(C1:C="";;SUBSTITUTE(FLATTEN(QUERY(TRANSPOSE(ROUND(
IFERROR(SPLIT(C1:C; "/")/MMULT(1*IFERROR(SPLIT(C1:C; "/"));
SEQUENCE(COLUMNS(SPLIT(C1:C; "/")); 1;;)^0))*100; 2));;9^9)); " "; " / ")))

Conditional mapping in GAMS

Consider the following data in GAMS:
set i / 1,2,3 /
j / 1,2,3 /;
parameter stock(i,j);
stock(i,j) = 10;
Consider the following mapping:
set jagg / b1,b2 /
map2(j,jagg) / 1.b1, 2.b1, 3.b2, 4.b2 /;
I can easily mapping using:
parameter stockagg(i,jagg);
stockagg(i,jagg) = sum(map2(j,jagg),stock(i,j));
However, I don't want to map if set i is equal to set j.
That is, I want the following data as my result:
1 1 10
1 b1 10
1 b2 20
2 b1 10
2 2 10
2 b2 20
3 b1 20
3 3 10
3 b2 10
4 b1 20
4 b2 10
4 4 10
Is there an easy way to do that in GAMS?
Not sure, if I got your question completely right, but this give you the result you posted:
set i / 1,2,3,4 /
j / 1,2,3,4,b1,b2 /;
Alias(j,jj);
parameter stock(i,j);
stock(i,j) = 10;
set jagg(j) / b1,b2 /
map2(j,jj) / 1.b1, 2.b1, 3.b2, 4.b2 /;
parameter stockagg(i,j);
stockagg(i,j) = sum(map2(jj,jagg(j))$(not sameas(i,jj)),stock(i,j))$(not sameas(i,j))
+ stock(i,j) $( sameas(i,j));
display stockagg;

Simplify equation after solving

In Maxima I put:
q_d: 1000-5*p_d;
q_s: -250+2*p_s;
p_d: (1+t)*p_s;
eq:q_d = q_s;
solve(eq,p_s);
EC: 10*q_d + 0.01 * (q_d**2);
get the result
p_s=1250/(5*t+7)
0.01*(1000-5*p_s*(t+1))^2+10*(1000-5*p_s*(t+1))
How do I further simplify EC in term of 't' only?
One way to go about this is to express all the relations you listed as equations, and then solve the equations for the variables you want to eliminate, then you get expressions in terms of t which you can substitute into EC to get a result only in terms of t.
(%i2) e1: q_d = 1000-5*p_d;
(%o2) q_d = 1000 - 5 p_d
(%i3) e2: q_s = -250+2*p_s;
(%o3) q_s = 2 p_s - 250
(%i4) e3: p_d = (1+t)*p_s;
(%o4) p_d = p_s (t + 1)
(%i5) e4: q_d = q_s;
(%o5) q_d = q_s
(%i6) solns: solve ([e1, e2, e3, e4], [q_d, q_s, p_d, p_s]);
1250 t - 750 1250 t - 750
(%o6) [[q_d = - ------------, q_s = - ------------,
5 t + 7 5 t + 7
1250 t + 1250 1250
p_d = -------------, p_s = -------]]
5 t + 7 5 t + 7
Now in %o6 I have a list of equations for the variables to be eliminated.
(%i7) EC: 10*q_d + 0.01 * (q_d**2);
2
(%o7) 0.01 q_d + 10 q_d
I'll substitute into EC to get a result in terms of t only.
(%i8) subst (solns[1], EC);
2
0.01 (1250 t - 750) 10 (1250 t - 750)
(%o8) -------------------- - -----------------
2 5 t + 7
(5 t + 7)
I'll use ratsimp to simplify the result.
(%i9) ratsimp (%);
rat: replaced 0.01 by 1/100 = 0.01
2
46875 t + 68750 t - 58125
(%o9) - --------------------------
2
25 t + 70 t + 49

Extracting sampled Time Points

I have a matlab Curve from which i would like to plot and find Concentration values at 17 different time samples
Following is the curve from which i would like to extract Concentration values at 17 different time points
following are the time points in minutes
t = 0,0.25,0.50,1,1.5,2,3,4,9,14,19,24,29,34,39,44,49. minutes samples
Following is the Function which i have written to plot the above graph
function c_t = output_function_constrainedK2(t, a1, a2, a3,b1,b2,b3,td, tmax,k1,k2,k3)
K_1 = (k1*k2)/(k2+k3);
K_2 = (k1*k3)/(k2+k3);
DV_free= k1/(k2+k3);
c_t = zeros(size(t));
ind = (t > td) & (t < tmax);
c_t(ind)= conv(((t(ind) - td) ./ (tmax - td) * (a1 + a2 + a3)),(K_1*exp(-(k2+k3)*t(ind)+K_2)),'same');
ind = (t >= tmax);
c_t(ind)= conv((a1 * exp(-b1 * (t(ind) - tmax))+ a2 * exp(-b2 * (t(ind) - tmax))) + a3 * exp(-b3 * (t(ind) - tmax)),(K_1*exp(-(k2+k3)*t(ind)+K_2)),'same');
plot(t,c_t);
axis([0 50 0 1400]);
xlabel('Time[mins]');
ylabel('concentration [Mbq]');
title('Model :Constrained K2');
end
If possible, Kindly please suggest me some idea how i could possibly alter the above function so that i can come up with concentration values at 17 different time points stated above
Following are the input values that i have used to come up with the curve
output_function_constrainedK2(0:0.1:50,2501,18500,65000,0.5,0.7,0.3,3,8,0.014,0.051,0.07)
This will give you concentration values at the time points you wanted. You will have to put this inside the output_function_constrainedK2 function so that you can access the variables t and c_t.
T=[0 0.25 0.50 1 1.5 2 3 4 9 14 19 24 29 34 39 44 49];
concentration=interp1(t,c_t,T)

Extract x-axis value using y-axis data in R

I have a time-series dataset in this format:
Time Val1 Val2
0 0.68 0.39
30 0.08 0.14
35 0.12 0.07
40 0.17 0.28
45 0.35 0.31
50 0.14 0.45
100 1.01 1.31
105 0.40 1.20
110 2.02 0.57
115 1.51 0.58
130 1.32 2.01
Using this dataset I want to extract(not predict) Time at which FC1=1 and FC2=1. Here is a plot that I created with annotated points I would like to extract.
I am looking for a solution using or function to interpolate/intercept to extract values. For example, if I draw a straight line at fold change 1 (say in y-axis), I want to extract all the points on X-axis where the line intercepts.
Looking forward for suggestions and thanks in advance !
You can use approxfun to do interpolations and uniroot to find single roots (places where the line crosses). You would need to run uniroot multiple times to find all the crossings, the rle function may help choose the starting points.
The FC values in your data never get close to 1 let alone cross it, so you must either have a lot more data than shown, or mean a different value.
If you can give more detail (possibly include a plot showing what you want) then we may be able to give more detailed help.
Edit
OK, here is some R code that finds where the lines cross:
con <- textConnection(' Time Val1 Val2
0 0.68 0.39
30 0.08 0.14
35 0.12 0.07
40 0.17 0.28
45 0.35 0.31
50 0.14 0.45
100 1.01 1.31
105 0.40 1.20
110 2.02 0.57
115 1.51 0.58
130 1.32 2.01')
mydat <- read.table(con, header=TRUE)
with(mydat, {
plot( Time, Val1, ylim=range(Val1,Val2), col='green', type='l' )
lines(Time, Val2, col='blue')
})
abline(h=1, col='red')
afun1 <- approxfun( mydat$Time, mydat$Val1 - 1 )
afun2 <- approxfun( mydat$Time, mydat$Val2 - 1 )
points1 <- cumsum( rle(sign(mydat$Val1 - 1))$lengths )
points2 <- cumsum( rle(sign(mydat$Val2 - 1))$lengths )
xval1 <- numeric( length(points1) - 1 )
xval2 <- numeric( length(points2) - 1 )
for( i in seq_along(xval1) ) {
tmp <- uniroot(afun1, mydat$Time[ points1[c(i, i+1)] ])
xval1[i] <- tmp$root
}
for( i in seq_along(xval2) ) {
tmp <- uniroot(afun2, mydat$Time[ points2[c(i, i+1)] ])
xval2[i] <- tmp$root
}
abline( v=xval1, col='green' )
abline( v=xval2, col='blue')

Resources