Count Unique values with a condition

Assuming no more than 100 rows try this “array formula” to count the different names in A2:A100 where there is a 1 in the same row in B2:B100: =SUM(IF(FREQUENCY(IF(B2:B100=1,IF(A2:A100<>””,MATCH(A2:A100,A2:A100,0))),ROW(A2:A100)-ROW(A2)+1),1)) confirmed with CTRL+SHIFT+ENTER Note that I say different not unique as the two are not the same

How to do a fractional power on BigDecimal in Java?

The solution for arguments under 1.7976931348623157E308 (Double.MAX_VALUE) but supporting results with MILLIONS of digits: Since double supports numbers up to MAX_VALUE (for example, 100! in double looks like this: 9.332621544394415E157), there is no problem to use BigDecimal.doubleValue(). But you shouldn’t just do Math.pow(double, double) because if the result is bigger than MAX_VALUE you will just … Read more

Method for evaluating math expressions in Java

There’s also exp4j, an expression evaluator based on Dijkstra’s Shunting Yard. It’s freely available and redistributable under the Apache License 2.0, only about 25KB in size, and quite easy to use: Calculable calc = new ExpressionBuilder(“3 * sin(y) – 2 / (x – 2)”) .withVariable(“x”, varX) .withVariable(“y”, varY) .build() double result1=calc.calculate(); When using a newer … Read more

Formula with dynamic number of variables

See ?as.formula, e.g.: factors <- c(“factor1”, “factor2”) as.formula(paste(“y~”, paste(factors, collapse=”+”))) # y ~ factor1 + factor2 where factors is a character vector containing the names of the factors you want to use in the model. This you can paste into an lm model, e.g.: set.seed(0) y <- rnorm(100) factor1 <- rep(1:2, each=50) factor2 <- rep(3:4, … Read more

Dynamically evaluate an expression from a formula in Pandas

You can use 1) pd.eval(), 2) df.query(), or 3) df.eval(). Their various features and functionality are discussed below. Examples will involve these dataframes (unless otherwise specified). np.random.seed(0) df1 = pd.DataFrame(np.random.choice(10, (5, 4)), columns=list(‘ABCD’)) df2 = pd.DataFrame(np.random.choice(10, (5, 4)), columns=list(‘ABCD’)) df3 = pd.DataFrame(np.random.choice(10, (5, 4)), columns=list(‘ABCD’)) df4 = pd.DataFrame(np.random.choice(10, (5, 4)), columns=list(‘ABCD’)) 1) pandas.eval This is … Read more