increment odd or even numbers in excel/openoffice calc? - excel

Im trying to increment in 1st column every even number by 1 and the 2nd column increment all odd numbers by 1.
what I manually have done so far:
48 4
4 49
49 4
4 50
50 4
2 51
51 2
2 52
52 2
2 53
as you can see in the 1st column every even number is incremented by 1 and in the 2nd column every odd number is incremented by 1. How can i do that automatically?
I mostly use open office calc, but I also have excel so either solution for both or one of them would be great!

You don't need code for this, it can be done using in-cell formulas.
When you want to increment all even numbers by one:
=ROUNDDOWN(A1 / 2, 0) * 2 + 1
When you want to increment all odd numbers by one:
=ROUNDUP(A1 / 2, 0) * 2
...where A1 is the name of the cell. Then just drag down the first row to extend the series into the entire column.

Related

Divide excel column to N equal groups

I have a column with ordinal values. I want to have another column that ranks them in equal groups (relatively to their value).
Example: If I have a score and I want to divide to 5 equal groups:
Score
100
90
80
70
60
50
40
30
20
10
What function do I use in the new column to get this eventually:
Score Group
100 5
90 5
80 4
70 4
60 3
50 3
40 2
30 2
20 1
10 1
Thanks! (I'm guessing the solution is somewhere in mod, row and count - but I couldn't find any good solution for this specific problem)
If you don't care about how the groups are split for groups that aren't evenly divisible, you can use this formula and drag down as far as necessary:
= FLOOR(5*(COUNTA(A:A)-COUNTA(INDEX(A:A,1):INDEX(A:A,ROW())))/COUNTA(A:A),1)+1
Possibly a more efficient solution exists, but this is the first way I thought to do it.
Obviously you'll have to change the references to the A column if you want it in a different column.
See below for working example.

Referencing the previous row in Spotfire and a value in another column

I'm trying to do something that is very simple to do in Excel, but seems very tricky in Spotfire:
Imagine you have the following table:
A
1: 10
2: 15
3: 20
... and you want to produce the following:
A B
1: 10 10
2: 15 25
3: 20 45
In other words, add the current value of A to the previous value of B. If this was Excel, the formula in cell B3 would be = A3 + B2... However, I'm not in Excel, I'm using Spotfire... :) Any thoughts?
NB: If it makes any difference to the answer at all, I will need to use the Intersect() function in conjunction with this, as there is a categorical column to factor in as well.
Hope this helps, I have considered the first column as ID
ID A B
1 10 10
2 15 25
3 20 45
If(Sum([A]) over (AllPrevious([ID])) is null,sum([A]) over ([ID]),Sum([A]) over (AllPrevious([ID])))

Find duplicates and count numbers at the same time

I have rows of data that contains numbers from 1 to 15, however these numbers can be in any sequence. For example here:
3 2 1 12 13 5 6 7 9 15 10 8 4 15 11
I know from a visual count these numbers above are all correct; as there are no duplicates, and all the numbers have values from 1 to 15. An example of a row of data I found to be wrong:
3 2 1 12 12 5 6 7 9 15 10 8 4 15
You can see this line has duplicated numbers i.e. 12, and number 11 is missing, so this row only has 14 elements in all.
However, I have many rows of data and it is impossible to visually check each row. I need to ensure in each row: there are 15 elements; there are no duplicates, and that the row contains values from 1 to 15 and find which rows are faulty to check these against the original paper data.
Is there a command or function that I can use in Excel to make this process easier?
You could find a set of conditions, each of which is true for rows that contain exactly those 15 numbers in any order and then test several of them. For example, if the row is in A5:O5:
=AND(COUNT(A5:O5)=15,SUM(A5:O5)=120,MIN(A5:O5)=1,MAX(A5:O5)=15,
AVERAGE(A5:O5)=8,ROUND(STDEV(A5:O5),3)=4.472)
This will show TRUE for a row that contains the integers 1 to 15 in any order, and is very unlikely (it could very well be impossible - I haven't checked) to show TRUE for a row that contains any different set of integers.
I'm pretty sure that the only way 15 positive integers less than 16 can add up to 120 other than by all being different is with duplication, so :
Check there are 15 numbers
Check their total is 120
Check the maximum is 15
Check not negative (nor zero):
=IF(OR(COUNT(A5:O5)<>15,SUM(A5:O5)<>120,MAX(A5:O5)>15,MIN(A5:O5)<1),"Error","Plausible")
then check for duplication with Conditional Formatting using a rule such as :
=COUNTIF($A5:$O5,A5)>1
and a distinctive format. Filter to select "Plausible" and then anything with a distnctive format is non compliant.

Extracting the upper quartile data from an array and placing it in new column

Hi and thanks for any help with this in advance
Below is a hypothetical data set; abundance = count data; mud% = the mud content in which the animals were found; mud bin = bins i've made up depending on the mud%; and UQ = upper quartile of the abundance data from its corresponding mud bin (i.e. the upper quartile for the abundance data in mud bin 1 is 17.25 etc).
Problem:
In excel, for abundance data in each of the four mud bins, I'm wanting to extract any values in the abundance column that are >= the upper quartile value for that particular mud bin and place these in a new column on the same sheet (with no gaps between rows from values that didn't meet the criteria) along with their corresponding mud% value in the neighboring cell. I've added the new columns to the below sheet to give you an idea of what I'm after.
abundance | mud% | mud bin | UQ | | New column | Mud% |
18 10.9 1 18 10.9(mud bid 1)
15 6.5 1 44 38.9(mud bin 1)
6 13.4 1 45 38 (mud bin 2)
13 42.1 1 37 37.8(mud bin 2)
15 36.4 1 etc
44 38.9 1 17.25 etc
22 46 2
30 36.4 2
45 38 2
29 35.3 2
37 37.8 2
29 41.8 2 35.25
11 44.4 3
17 47.8 3
21 40.7 3
15 13.9 3
35 13.9 3
14 13.9 3
15 13.9 3 19
19 12 4
14 12 4
10 12 4
12 12 4
14 12 4
13 12 4
45 9.525 4
66 9.525 4
78 9.525 4 45
The reality is I have a rather large dataset containing abundance data for a number of species, all on the same excel sheet and would greatly appreciate any insight into how I might achieve this in the most efficient manor.
For starters, to make this explanation simpler, I will assume that the last row of data is in row 100.
Populate Upper Quartile values for all line items
First you'll need to use the Quartile formula; however, since you want to find the upper quartile within a bin, you'll have to use an array formula. Put this formula in your UQ column (place in cell D2 and drag down). When entering the formula Be sure to press Ctrl+Shift before pressing Enter
=QUARTILE(IF($C$2:$C$100=C2,$A$2:$A$100,""),3)
The first part of this formula, $C$2:$C$100=C2 is your condition. Everywhere this condition is met, you will get the corresponding value in $A$2:$A$100; otherwise, you'll get a blank value. This will give you an array of abundance values that matches the indicated mudbin, C2. now that you have your subset of data, the quartile function will give you the value in the 3rd quartile (17.25 for mudbin 1, which will be placed next to every row that has a mudbin of 1).
Now that we have all the quartiles, we can get all the abundance values that are greater than the UQ for that mudbin. This is done in two parts
Get abundance values greater than mudbin UQ
First, you need to select one column of cells that has the same number of rows as your data (for example, select cells F2:F100)
Enter the following formula into the formula bar (while F2:F100 are highlighted) and press Ctrl+Shift, then enter
=IF($A$2:$A$100>$D$2:$D$100,$A$2:$A$100,"")
Similar to the IF statement used before, this formula finds all the abundance values that are greater than their corresponding UQ value. Now column F will have an abundance number where it is greater than it's UQ value, and a blank where it is not. Now onto the final step.
Populate abundance values that are greater than the UQ value, without the blanks
Select G2:G100 (your "New Column" in your sample data)
Enter the following formula into the formula bar (while G2:G100 are highlighted) and press Ctrl+Shift, then enter
=INDEX(F2:F100,SMALL(IF(F2:F100<>"",ROW(F2:F100)-1),ROW()-ROW($F$1)))
Looking at the IF statement again, this will find every value in F2:F100 that is not blank, but instead of grabbing the values, we'll keep track of the row number of that non blank value (done by ROW(F2:F100)-1
). Now that we have the row numbers of all the non blank values, we can grab the non-blank values in order and populate them in G2:G100. ROW()-ROW($F$1) is a counter, and SMALL will use the counter to determine the nth smallest number to return. Once we have our row number of the non blank value, INDEX returns that value
Finally, to populate the Mud%, you'll need to use the row number of the non blank values to get the mud% and the mud bin (You have the formula already to get the row number of the non blank value).
It's not a simple answer, but at least you won't have to use VBA.

Excel: Find the minimal value in a column

An Excel table consists of two columns (e.g., A1:B5):
0 10
1 20
3 30
2 20
1 59
I need to get the minimal value in column B for which the corresponding value in column A is greater than zero. In the above example it should be 20.
I tried using various combinations of INDEX(), MIN(), IF(), ROW(), array formulas, etc. - but I just can't figure out how to do it. :-( Any help would be appreciated.
Grsm almost had it
if you enter the following formula in C1 as an array (Ctrl+Shift+End)
=MIN(IF(A1:A5>0,B1:B5))
That should do the trick.
I think you have to make an extra column..
A B C D
0 10 false 20
1 20 20
3 30 30
2 40 40
1 50 50
column C : =IF(A1>0;B1)
cell D1: =MIN(C1:C5)
You need to do it in 2 stages
First use the MIN function to find the minimum
Then take that answer and use the LOOKUP function to select the row and column that you need.
Check the "Minimum And Maximum Values In A Range" example in http://www.cpearson.com/Excel/excelF.htm (you can download the same as well from the same section)
HTH
This is not identical, but very similar: Excel VBA - Find minimum of list of values?

Resources