Need a formula to sort Excel column by - math

Please have a look at this spreadsheet
I need a formula that would put the green rows at the top or near the top at least and the red rows at or near the bottom the column is sorted. It doesn't have to work for any numbers, just the ones in this spreadsheet
I got close with by sorting by column D which has (columnA / columnB * 100) * columnA but there are green outlier rows in the middle that should be more towards the top area

You say nothing about the line colored tan (near-red), so I treat that as a red line.
Put a new formula in E2,
=IF(A2<5,100,0)+IF(C2>0.68,0,10)-D2/10000
then copy it down column Sort the table on column E, increasing. You then get this:
This works because the green rows are distinguished in their column C, which is 0.667 or less for green and 0.700 for all other rows. The red rows are distinguished in their column A, which is 2 or less for red (and for the tan) and 7 or more for all other rows. So my formula makes breakpoints at 5 for column A and 0.68 for column C and assigns appropriate numbers, adding them for a final score. I use column D as a tie-breaker, as in your original data. You can remove the -D2/10000 if you don't care about tie-breakers in each color section.
I did all this in Microsoft Excel (in Office 365), as in your question title.

Related

Permutation Combination question (3*n board)

I have a question:
Find the total number of ways a 3×n board can be painted using 3 colors while making sure no cells of the same row or the same column have entirely the same color. The answer must be computed modulo 10^9+7.
Also somebody answered it here.
https://math.stackexchange.com/questions/3215805/coloring-a-3-times-n-board-using-3-colors
but i am not able to understand, can you explain in easy language?
To understand the general principle, let's look at a situation with only two columns. Name the colors red, green and blue.
For a column to fulfill the conditions: Each cell can have one of 3 colors, there are 3 cells, totaling 3^3=27 possible colorings. Among these, 3 are monochrome (one red, one green, one blue). Subtracting the disallowed colorings: 27-3=24 possibilities for a column. Only considering the columns, there are 24^n colorings for the board.
Now, let's look at the disallowed rows. For the monochrome row, there are 3 colors and 3 possible rows to choose from. For each of these 9 possibilities, each column can be colored in 8 possible ways. This means 9x8^n rows need to be removed. The image below shows each of the possible boards where no column is monochrome. The 9x8^2=576 rows to be removed are shown with a black line:
If we now subtract the number of blacked out rows from the total, we are subtracting too many: some boards have two bad rows and some even three.
So, the count of the boards with two bad rows has to be added again. Their total is 3x3x2^n + 3x6x3^n. The first term counts the case with two equal colored bad rows: 3 positions for the non-bad row, 3 colors for the bad rows, 2 remaining colors for each cell of the non-bad row. The second term counts the case with two differently colored bad rows: 3 positions for the non-bad row, 6 possible colorings for the bad rows, 3 possible colors for each cell of the non-bad row.
There are 24 boards with three bad rows which got subtracted three times in the second step and added again three times in the third step. They now have to be subtracted from the total.
So, as explained in the linked post, the general formula is:
24^n − 9×8^n + 18×3^n+9×2^n − 24
which gives the values 0, 174, 9750, 296490, 7672350, 188757354, 4567637550, 109924439610, 2640599939550, 63393718361034, ... for n starting at 1.
Or modulo 10^9+7:
0, 174, 9750, 296490, 7672350, 188757354, 567637522, 924438847, 599921070, 717917283, ...

Assign integral value to list of relative values

I have an assortment of syrups, each of which has a value - the amount of sugar per volume. As people blend these syrups, I track which ones are used, and created a table to get a Relative Weight of each blend. I understand > Data > Sort > Options > Custom Sort Order.
However, I really don't wish to sort each table, and am looking for a way to parse a column of this list as entered, and return a column with results in an Integral Relative Value of each row, as compared to the weights of syrups in the other rows of the table.
Unique Name weight Not Unique Relative Value
blueberry .250 2
raspberry .333 3
orange .425 4
tangerine .333 3
blackberry .225 1
I am attempting to find the "Relative Sort", a nested function which can assign an integral value of the Unique Name which compares the weights of the syrups. A "Lookup" only works if there is an absolute equality, right?
What if someone doesn't use "blackberry syrup", then "blueberry" is the lightest, and should be labeled as 1.
Is this too complicated for LibreOffice Calc?
It's a recursive greater than/less than/equal to comparison?
IF the problem is calculating the right hand column below from entries that may be sorted ascending by value as on the left:
then an answer is, in C2 and copied down to suit (provided C1 is blank or 0):
=IF(B1<>B2,C1+1,C1)
Without sorting the RANK function might be simpler and adequate (though in the example returning 5 rather than 4).

In Openoffice, Calc, to index areas under condition, between two words

In Openoffice, Calc, to index areas under condition, between two e.g. words?
E.g. in a column A, one under another "A,B,D,c,A,B,C,A,C)...
I want each time to index only A to C, and when results are reported with Match functions (of corresponding column B values), to continue to the next region AC. How can i do this in #Calc?
1rst region:ABDC,
2nd:ABC,
3rd:AC
In cell B1 enter 1, then in cell B2 enter =IF(A2="A";B1+1;B1)
Copy cell B2 and paste down however many rows your pattern is. Calc will automatically adjust the formula to increase the row numbers as you paste in lower rows. This formula will go up by 1 whenever the pattern has an A, otherwise it will repeat the number from the previous row.
Note that it is case-sensitive and will not increment for a. If you want either case (A or a) to trigger the increment, use =IF(OR(A2="A";A2="a");B1+1;B1)

Filtering grouped data in R

I was wondering if anyone can help with grouping the data below as I'm trying to use the subset function to filter out volumes below a certain threshold but given that the data represents groups of objects, this creates the problem of removing certain items that should be kept.
In Column F ( and I) you can see Blue, Red, and Yellow Objects. Each represent three separate colored probes on one DNA strand. Odd numbered or non-numbered Blue ,Red, and Yellow are paired with a homologous strand represented by an even numbered Blue, Red, and Yellow. Ie data in rows 2,3,and 4 are one "group" and pair with the "group" shown in rows 5,6,and 7. This then repeats, so 8,9,10 are a new group and that group pairs with the one in 11,12,13.
What I would like to do is subset the groups so that only those below a certain Distance to Midpoint (column M) are kept. The Midpoint here is the midpoint of the line that connects the blue of one group with the blue of its partner, so the subset should only apply to the Blue distance to midpoint, and that is where I'm having a problem. For instance if I ask to keep blue distances to midpoint that are less than 3, then the objects in row 3 and 4 should be kept because they are part of the group with the blue distance below 3. Right now though when I filter with the subset function I lose Red Selection and Yellow Selection. I'm confident there is a straighforward solution to this in R, but I'd also be open to some type of filtering in excel if anyone has suggestions via that route instead.
EDIT
I managed to work something out in Excel last night after posting the question. Solution isn't pretty but it works well enough. I just added a new column next to "distance to midpoint" that gives all the objects in one group the same distance so that when I filter the data I won't lose any objects that I shouldn't. If it helps anyone in the future, the formula I used in excel was:
=SQRT ( ((INDEX($B$2:$B$945,1+QUOTIENT(ROWS(B$2:B2)-1,3)*3))- (INDEX($O$2:$O$945,1+QUOTIENT(ROWS(O$2:O2)-1,3)*3)) ) ^2 +( (INDEX($C$2:$C$945,1+QUOTIENT(ROWS(C$2:C2)-1,3)*3))-(INDEX($P$2:$P$945,1+QUOTIENT(ROWS(P$2:P2)-1,3)*3)) ) ^2 +( (INDEX($D$2:$D$945,1+QUOTIENT(ROWS(D$2:D2)-1,3)*3))-(INDEX($Q$2:$Q$945,1+QUOTIENT(ROWS(Q$2:Q2)-1,3)*3)) ) ^2)
Would be easier with a reproducible example, but here's a (hacky) plyr solution:
filterframe<-function(df,threshold){
df$grouper<-rep(seq(from=1,to=6),nrow(df)/6)
dataout<-df%>%group_by(grouper)%>%summarise(keep=.[[1]]$distance_to_midpoint<threshold)
dataout[dataout$keep,]
}
filterframe(mydata)
A base R solution provided below. The idea is that once your data are in R, you (edit) keep! rows iff they meet 2 criteria. First, the Surpass column has to contain the word "blue" in it, which is done with the grepl function. Second, the distance must below a certain threshold (set arbitrarily by thresh.
fakeData=data.frame(Surpass=c('blue', 'red', 'green', 'blue'),
distance=c(1,2,5,3), num=c(90,10,9,4))
#thresh is your distance threshold
thresh = 2
fakeDataNoBlue = fakeData[which(grepl('blue', fakeData$Surpass)
& fakeData$distance < thresh),]
There's probably also a quick dplyr solution using filter, but I haven't fully explored the functionality there. Also, I may be a bit confused on if you also want to keep the other colors. If so, that's the same as saying you want to remove the blue ones exceeding a certain distance threshold, which you would just do a -which command, and turn the < operator into a > operator.

How to create excel formula that will add an number to specific digits in a multi digit number

Ex: I enter the number 9876543210 in a cell.
I want to create an if then formula to add a sequential number to this but working only off of the last digit. the zero in this example.
If the last digit is >= to 3 than add 5 if the last digit is <=2 than add 15.
Then have this formula repeat for 10 numbers - is that possible?
so i imput the 9876543210
it then show:
9876543225
9876543230
9876543245
and so on
=IF((RIGHT(A1,1)/1)>2,A1+5,A1+15)
Assumed that you update the number in the cell A1. Paste the above formula in A2 and copy paste downwards.
If this is Excel, you may want to use MOD (modulo or remainder) function to get the last digit and then perform an IF-THEN or nested IF-THEN to achieve this.
=IF(MOD(A1,10)=3, A1+15, IF(MOD(A1,10)=5, A1+20, A1+30))
This formula translates to the following decision tree:
IF the last digit of the value in cell A3 is 3 Then
Add 15 to it
ELSEIF the last digit of the value in cell A3 is 5 then
Add 20 to it
ELSE
Add 30 to it
END IF
Repeating the operation may require some VBA. If you already know the number of times you need to repeat the operation, you can pre-populate formulas in subsequent rows/columns, each time refer to the immediately preceding cell. For example, if you want to repeat it 5 times, you should compute the diff of first two cells and then add that diff to the value of immediately preceding row/column like this (assuming A1 had the original value, B1 had the formula I posted above and C1 through G1 are the next 5 cells):
In C1: =B1 + ($B1 - $A1)
In D1: =C1 + ($B1 - $A1)
and so on...
Note the use of absolute and relative addresses in these formulae. You can copy/paste the formula in C1 to the subsequent cells and it will automatically adjust itself to refer to immediately preceding cell.
EDIT
I just realized that you want to evaluate the MOD formula in each subsequent cell. In that case you simply need to copy/paste it to subsequent cells instead of using 2nd and 3rd formulas I posted above.

Resources