Formula to check blank cells between 2 cells with data and continue to do for the specified range - count

Is there a formula to check the no of blank cells, between 2 cells with data give the no of blank cells, and further continue to check for same criteris for specified range of cells.

Related

Compare Column Values to Mean and Associate 2 Column Names in R studio

The following are the 2 initial columns of our dataset. The column on the left (with numbers) was inserter by R.
The following is another column in our dataset.
We have calculated the mean of all values in this column.
We wish to compare each of the values in this last column to the mean value. (Is it higher, equal or lower than then mean value?).
To do so we used he following code:
which(databel$coverage>0.1632407, useNames=TRUE)
which(databel$coverage<0.1632407, useNames=TRUE)
which(databel$coverage==0.1632407, useNames=TRUE)
Where 0.1632407 is equal to the calculated mean of the column in the second immage.
However, this returns a list of the row number (found on the left side of the first image) rather than the place name (found on the right side of the first image)
How can we have it return the corresponding place name?
Because which returns the indices, we can use the return value to subset the databel$Thema vector to get the names.
databel=data.frame(Thema=c("Aalst", "Aalter", "Aarschot", "Aartselaar", "Affligem", "Alken", "Alveringem", "Anderlecht"),
coverage=c(.14,.17,.15,.13,.15,.18,.14,.16), stringsAsFactors = FALSE)
databel$Thema[which(databel$coverage>mean(databel$coverage))]
"Aalter" "Alken" "Anderlecht"
databel$Thema[which(databel$coverage<mean(databel$coverage))]
"Aalst" "Aarschot" "Aartselaar" "Affligem" "Alveringem"
databel$Thema[which(databel$coverage==mean(databel$coverage))]
character(0)

How can a formula be used in scalc (Apache OpenOffice) to count cells with content, while the count should stop at the first empty cell?

Here (https://www.howtoexcel.org/formulas/how-to-find-the-position-of-the-first-non-blank-cell-in-a-range/) is a source for Excel where the following formula is described:
{=MATCH(FALSE,ISBLANK(B3:B9),0)}
The count should stop at b because the following cell is empty or contains no printable character. The result should be 2.
=COUNTA(A30:A50) ; A29
a
b
c
There is no need to use a count function because we can subtract 1 from the matched index to get the count. Also, to find the first blank cell, the search criterion should be true, not false.
=MATCH(TRUE();ISBLANK(A30:A50);0)-1
a
b
c
Result: 2
In LibreOffice Calc, this works when entered normally. In Apache OpenOffice, it must be entered as an array formula with Ctrl+Shift+Enter.

explicit the x-value for plotting in gnuplot

In GNUPLOT, I would like to plot 5 values on a single bar chart, separated with some spacing in between. If I have data formatted as such:
3342336, 3375103, 7110653, 32770, 0
where those 5 values are the y-values, how can I specify the x-values myself for where they should belong?
For example, I would like my bar chart to have each entry be of length 1,
so I plot y-value 3342336 at x-value 1,
y-value 3375103 at x-value 3,
y-value 7110653 at x-value 5,
y-value 32770 at x-value 7,
and y-value 0 at x-value 9.
I would appreciate any example code that can achieve this. Thanks.
If your data is in one row as shown, you can achieve this by using the plot for syntax looping over the column index, and calculating the x value from that index. We can grab the column by using the column function which retrieves the specified column number.
set boxwidth 1
set datafile separator comma # only if data is comma separated
plot for [i=1:5] (2*i-1):(column(i)) with boxes
If we need to ensure the same line type is used each time, we can explicitly state it in the plot command.
plot for [i=1:5] (2*i-1):(column(i)) with boxes lt 1
Additionally, if a key is to be generated, and we don't wish each plot statement to generate one, we can test for and only give a nonempty title on the first iteration (an empty title is treated the same as no title).
plot for [i=1:5] (2*i-1):(column(i)) with boxes lt 1 title (i==1)?"Title":""
If your data is separated into rows as is the normal format, this can be obtained a different way.
Gnuplot has several pseuduocolumns (see help pseudocolumns for details). In your case, column 0 is of interest. Column 0 gives the line number of the data starting at 0. Thus to get sequential odd numbers like that, you can use 2*$0+1.
For example, if your data (stored in datafile.txt) looks like
3342336
3375103
7110653
32770
0
and you wish to plot boxes of length 1 at those values, you can do
set boxwidth 1
plot "datafile.txt" u (2*$0+1):1 with boxes

COUNTIF where criterion is a specific sequence of cells

I'm doing some work with arithmetic sequences modulo P, in which the sequences become periodic under the modulo. My worksheet generates a sequence mod P with the first term being 0, the second term being a number K (referencing another cell), and the following terms following the recurrence relation. The period of the sequence (number of values before it repeats itself) is related to the ratio P/K, s, for example, if P=2 and K=1, I get the sequence {0,1,1,0,1,1,0,1,1,...}, which has a period of 3, so when P/K=2, the period is 3.
I currently have a formula which uses the COUNTIF function to count the number of zeroes in the range, which is then divided out of the total range, currently an arbitrary size of 120, and this gives me the correct period for many ratios of P/K. Most of the time, however, the sequence generated exhibits semi-periodicity and sometimes even quasi-periodicity, such as in the case of K=1 and modulo 9: {0,1,1,2,3,5,8,4,3,7,1,8,0,8,8,7,6,4,1,5,6,2,8,1,...}, where P/K=9, the period is 24, and the semi-period is 12 (because of the 0,8,8,... part of the sequence). In such cases, my current COUNTIF formula thinks the full period is 12, even though it should be 24, because it counts the zeroes which define the semi-period.
What I would like to do is adjust the formula so that instead of the criterion for counting being 0, it would only count triplet sequences of cells in the pattern 0,K,K.
My current formula:
=QUOTIENT(120,(COUNTIF(B2:DQ2,0)))
So if I have =QUOTIENT(120,(COUNTIF(B2:DQ2,*X*))) I want the "X", which is currently 0, to reference a specific sequence of cells, namely the first three of the overall series, so something like: =QUOTIENT(120,(COUNTIF(B2:DQ2,(0,C2,D2)))) although obviously that criterion is not in remotely the correct syntax.
I'm not well-versed in writing macros, so that would probably be out of the question.
I would do this with four helper rows plus the final formula. Someone more clever than I am might be able to do it in one cell with an array formula; but compared to array formulas I think the helper rows are easier to understand and, if desired, tweak.
Once this is set up, if you're always going to use three as your criterion, you can hide the helper rows (to hide a row, right-click on the gray number label on the left side of the spreadsheet, and choose "hide").
So your sequence is in row 2, starting in column B. We'll set up the first helper row in row 3, starting in column C. In cell C3 put the formula =C2=$B$2. This will evaluate to FALSE, which is equivalent to 0. Copy and paste that formula all the way to cell DQ3 (or however many columns you want to run it). Cells below a sequence number equal to the first number in the sequence will evaluate to TRUE, which is equivalent to 1.
The next two helper rows are very similar. In cell D4 put the formula =D2=$C$2 and copy and paste to cell DQ4. This row tests which cells are equal to the second number in the sequence.
In cell E5 put the formula =E2=$D$2 and copy and paste to cell DQ5, showing which cells are equal to the third number in the sequence.
The last helper row is a little different, so I left an empty row after the first three helpers. In cell E7 I put the formula =SUM(C3,D4,E5); copy and paste that over to column DQ. This counts how many matches were found in the previous three helper rows. If all three match, the result of this formula will be 3 and your criterion for determining the period will have been fulfilled.
Now to show the period: in the cell you want to have this number, put the formula =MATCH(3,E7:DQ7,0). This searches the last (fourth) helper row looking for a cell that is equal to 3. (Obviously you could modify this method to match only the first two sequence numbers, or to match more than 3, and then you'd adjust the first parameter in the MATCH formula.) The last parameter in this MATCH formula is 0 because the helper row is not sorted. The return value is the index of the first match: a match in E7 would be index 1, a match in E8 would be index 2, etc.
I tested this in LibreOffice 4.4.4.3.

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