Questions tagged [multiple-conditions]

Examples include if, for, while and other loops.

while (a==1 && b==2)
{
   ...
}

The loop will continue as long as a is 1 and b is 2.

630 questions
4
votes
3 answers

How to sum rows based on multiple conditions - R?

I have a dataframe that contains a plot ID (plotID), tree species code (species), and a cover value (cover). You can see there are multiple records of tree species within one of the plots. How can I sum the "cover" field if there are duplicate…
Borealis
  • 8,044
  • 17
  • 64
  • 112
4
votes
1 answer

Using multiple conditions in awk

I want to extract the information from a large file based on multiple conditions (from the same file) as well as pattern searching from other small file, Following is the script I used: awk 'BEGIN{FS=OFS="\t"}NR==FNR{a[$0]++;next}$1 in a {print…
Maulik Upadhyay
  • 127
  • 1
  • 12
4
votes
1 answer

XML Xpath - select where element = multiple values

Fairly straightforward question, but seems pretty hard to find what I want through search, here or Google. Most people ask how you can select a node/ element with multiple conditions. Like URL/books[title="Harry Potter" and author="JKRowling"] I…
John Babson
  • 51
  • 10
4
votes
3 answers

Simplify nested case when statement

Below is my current SELECT CASE statement: SELECT CASE WHEN edition = 'STAN' AND has9 = 1 THEN '9' WHEN edition = 'STAN' AND has8 = 1 THEN '8' WHEN edition = 'STAN' AND has7 = 1 THEN '7' WHEN edition = 'STAN' AND hasOLD = 1 THEN 'OLD' WHEN edition…
coala
  • 235
  • 2
  • 5
  • 14
4
votes
1 answer

How to fix a while loop with multiple conditions returning an error

I have written code requesting the user to either type "2012" or "2013". I then have a while loop check to see if the user types 2012 or 2013. The request to enter a valid year is supposed to continue until the user enters a valid number. …
Jonathan Charlton
  • 1,975
  • 6
  • 23
  • 30
4
votes
2 answers

specific tuples generation and counting (matlab)

I need to generate (I prefere MATLAB) all "unique" integer tuples k = (k_1, k_2, ..., k_r) and its corresponding multiplicities, satisfying two additional conditions: 1. sum(k) = n 2. 0<=k_i<=w_i, where vector w = (w_1,w_2, ..., w_r) contains…
michal
  • 239
  • 2
  • 9
3
votes
1 answer

Finding unique combinations that fulfill a given set of conditions

I'm trying to find the unique combinations that fulfill the given criteria, sorted by cost. An example: Criteria: [A, B, C, D] Entities: [ E1 = (costs = 5, covers = [A, B, E]), E2 = (costs = 5, covers = [C, D]), E3 = (costs = 2, covers =…
BFMeenink
  • 33
  • 5
3
votes
4 answers

ranking dataframe using two columns in R

I am new to using R, and I am having hard time trying to rank dataframe using two columns in R. The data is in the form of this. A B 1 1 2 1 2 1 4 4 5 3 I want result to be in the form of A B Rank 1 1 1 2 1 2 2 1 2 4 4 5 5 3 4 which is ranked by B…
3
votes
4 answers

cumulative sum by ID with lag

I want to create a cumulative sum by id. But, it should not sum the value that belongs to the row where is being calculated. I've already tried with cumsum. However, I do not know how to add a statement which specifies to do not add the amount of…
Magggggg
  • 67
  • 7
3
votes
2 answers

Shorter condition in the filter pipe

I have a pipe, that filter dates of clients. Now it looks like: import { Pipe, PipeTransform } from '@angular/core'; @Pipe({ name: 'filter' }) export class FilterPipe implements PipeTransform { transform(clients: any[], searchText: string):…
3
votes
1 answer

Filtering with dplyr by using two separate selection criteria involving two columns

I'm trying to conditionally filter a data frame to extract the rows of interest. What I'm trying to do is different than generic conditional filtering in that it involves variable rules affecting the pairs of columns. My reprex below simulates a…
Atakan
  • 416
  • 3
  • 14
3
votes
1 answer

postgresql left join multiple conditions

I am still a NB to PostgreSQL - can anyone help with this query: select distinct j.id, tt.title, m_scopus.provider_id from journal j join temporal_title "tt" on (j.id = tt.journal_id and tt.list_index = 0) left join journal_metrics…
pmelch
  • 101
  • 1
  • 3
  • 9
3
votes
2 answers

Print array values based in sorting list and ascending order

Please your help. I have the array "values" that I want to sort by 2 conditions. First condition: Using the sort list defined in array "sortlist". Second condition: From smallest to largest. With my current script I've been able to print the values…
Ger Cas
  • 2,188
  • 2
  • 18
  • 45
3
votes
2 answers

I use OR to form a multiple condition IF ELSE statement on VBA, it's not working

Dim cat As Integer For cat = 2 To last Range("AB" & cat).Select If Selection.Value = " " Then ActiveCell.Offset(0, -2).Value = "-" ActiveCell.Offset(0, -1).Value = "-" ElseIf Selection.Value = "Address in local wording"…
gonzalloe
  • 313
  • 3
  • 7
  • 22
3
votes
4 answers

ruby unless bug with multiple conditions

Common Code: class ThingA end class ThingB end class ThingC end In order to set up conditional checks for the above types, I used the basic "if !..." construct that produced the accurate results as expected. Sample Code if ! ...: obj =…
ThunderThunder
  • 148
  • 1
  • 7
1 2
3
41 42