multiple-conditions

Bash IF : multiple conditions

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 13:09:27
问题 I've been trying to make this thing work for a couple of hours but I can't get it to work : if [ "$P" = "SFTP" -a "$PORT" != "22" ] || [ "$P" = "FTPS" && [ "$PORT" != "990" -a "$PORT" != "21" ] ] ; then Can someone help me ? I know that multiple conditions can be written like this : if [ "$P" = "SFTP" ] && [ "$PORT" != "22" ]; then but how can I imbricate theses conditions like in my first example? 回答1: You can't nest expressions in single brackets. It should be written like this: if [ "$P" =

Count xml elements with multiple conditions and precise properties

我与影子孤独终老i 提交于 2019-12-11 11:08:22
问题 I have the following code (xml and xslt) and I would like to count some xml elements with 2 conditions. XMLcode: <home> <place Value='place1'> <property Name="Type" Value="house" /> <property Name="Context" Value="roof" /> <property Name="Color" Value="blue" /> </place> <place Value='place2'> <property Name="Type" Value="house" /> <property Name="Context" Value="kitchen" /> <property Name="Color" Value="red" /> </place> <place Value='> <property Name="Type" Value="house" /> <property Name=

Sum by group with multiple logical conditions while omitting values from sum R data.table

不问归期 提交于 2019-12-11 09:28:24
问题 I am having trouble figuring out how to sum rows in a data.table while omitting the values of a certain group in the process. Let's say I have a data.table of the following form: library(data.table) dt <- data.table(year = c(2000, 2001, 2002, 2003, 2000, 2001, 2002, 2003, 2000, 2001, 2002, 2003, 2000, 2001, 2002, 2003), name = c("Tom", "Tom", "Tom", "Tom", "Fred", "Fred", "Fred", "Fred", "Gill", "Gill", "Gill", "Gill", "Ann", "Ann", "Ann", "Ann"), g1 = c(1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1,

Consecutive exceedance above a threshold and additional conditions in R

末鹿安然 提交于 2019-12-11 04:59:16
问题 I would like to get the time step in a time series satisfying the following conditions using R (should be the first time step satisfying the following conditions): [1] V1 > 0 at the time step [2] V1 > 0 in at least 3 consecutive time steps from the timestep obtained in [1] [3] Accumulated value of the next four timesteps following [1] should be greater than 1. Here's the data structure(list(V1 = c(-3.85326, -2.88262, -4.1405, -3.95193, -6.68925, -2.04202, -2.47597, -4.91161, -2.5946, -2.82873

get subsection of df based on multiple conditions

久未见 提交于 2019-12-10 13:18:09
问题 I'm trying to extract rows from a df based on multiple conditions, ALL of the conditions must be met before any rows are selected else nothing. My df columns = ['is_net', 'is_pct', 'is_mean', 'is_wgted', 'is_sum'] index = ['a','b','c','d'] data = [['True','True','False','False', 'False'], ['True','True','True','False', 'False'], ['True','True','False','False', 'True'], ['True','True','False','True', 'False']] df = pd.DataFrame(columns=columns, index=index, data=data) df is_net is_pct is_mean

Testing multiple string 'in' conditions in list comprehension [duplicate]

心已入冬 提交于 2019-12-10 12:33:24
问题 This question already has answers here : How to test multiple variables against a value? (24 answers) Closed last year . I am trying to add multiple 'or' clauses to a python if statement using list comprehension. My code is shown below. I would like to keep the list comprehension. In terms of pseudocode, the logic would simply be: Alive_Beatles = each name that contains '(Beatle)' and either ('Paul', 'Yoko' or 'Ringo') The code only returns Paul and skips Ringo and Yoko. Names = ["John Lennon

Multiple query conditions in Rails - if they exist.

别说谁变了你拦得住时间么 提交于 2019-12-05 10:50:33
I found a few similar questions while searching here, but when I tried to add unless to the solutions I found, things started to break... Here's what I have that works: Controller: @metrics = Metric.where("current_ratio > ?", @screen.current_ratio_min) unless @screen.current_ratio_min.nil? Once I add another .where line (of which I need to add many), @metrics = Metric.where("current_ratio > ?", @screen.current_ratio_min) unless @screen.current_ratio_min.nil? .where("current_ratio < ?", @screen.current_ratio_max) unless @screen.current_ratio_max.nil? I get an error: undefined method `where' for

Using a combination of ANDs and ORs in Mongoid

天大地大妈咪最大 提交于 2019-12-05 10:27:46
I'd like to construct a query of the form: select * from some_table where (field1 = 'x' or field2 = 'y') and (field3 = 'z' or field4 = 'w') From reading the docs, I thought it should look something like this in Mongoid : SomeTable.or({:field1 => 'x'}, {:field2 => 'y'}) .and # or is it .intersect? .or({:field3 => 'z'}, {:field4 => 'w'}) But then that doesn't work - the mongo selector is simply an "$or" of all the fields. What's the correct way to do this? thanks. I'd also appreciate the inverse of that, e.g - how to perform this query: select * from some_table where (field1 = 'x' and field2 =

How to sum rows based on multiple conditions - R? [duplicate]

久未见 提交于 2019-12-04 15:33:03
This question already has an answer here: How to sum a variable by group 13 answers 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 "species" rows within each plot? For example, here is some sample data: # Sample Data plotID = c( "SUF200001035014", "SUF200001035014", "SUF200001035014", "SUF200001035014", "SUF200001035014", "SUF200046012040", "SUF200046012040", "SUF200046012040", "SUF200046012040",

Scala filter on two conditions

瘦欲@ 提交于 2019-12-03 08:06:32
问题 I would like to filter my data set on two conditions at once. Is it possible? I want something like this: mystuff = mystuff.filter(_.isX && _.name == "xyz") 回答1: Using slightly less concise lambda syntax: mystuff = mystuff.filter(x => (x.isX && x.name == "xyz")) You can find more detail on Scala anonymous function syntax here. 回答2: While there might be some performance impact depending on what "myStuff" is, you could always filter twice mystuff = mystuff.filter(_.isX).filter(_.name == "xyz")