matching

Partial animal string matching in R

霸气de小男生 提交于 2019-11-28 18:51:30
I have a dataframe, d<-data.frame(name=c("brown cat", "blue cat", "big lion", "tall tiger", "black panther", "short cat", "red bird", "short bird stuffed", "big eagle", "bad sparrow", "dog fish", "head dog", "brown yorkie", "lab short bulldog"), label=1:14) I'd like to search the name column and if the words "cat", "lion", "tiger", and "panther" appear, I want to assign the character string feline to a new column and corresponding row species . If the words "bird", "eagle", and "sparrow" appear, I want to assign the character string avian to a new column and corresponding row species . If the

get all ranges of a substring in a string in swift

拜拜、爱过 提交于 2019-11-28 14:19:12
I have a string for example "ab ad adk fda kla kad ab ab kd". I want to get all range of ab.(Here ab is present at 3 position so I should get 3 range).In normal scenarion my code is working fine, but if search text is ".",then I am getting wrong result do { let regEx = try NSRegularExpression(pattern: searchText, options: NSRegularExpressionOptions.CaseInsensitive) let matchesRanges = regEx.matchesInString(attributedText.string, options:[], range: NSMakeRange(0, attributedText.string.length)) for rng in matchesRanges { let wordRange = rng.rangeAtIndex(0) } } catch { ... } The following

How to create a binary vector with 1 if elements are part of the same vector?

▼魔方 西西 提交于 2019-11-28 13:35:42
I would like to create a so-called matching vector consisting of binaries. All numbers should be zero unless elements belong to the same variable. Here's an example: dataset=("a","b","c","d","x","y","z") var1=c("a","b","y","z") var2=c("c","d","x") Thus, I have a dataset with all the variables in the first line. Now I create two groups: var1 and var2. The matching vector for the element "a" is supposed to look like: matching_a=c(1,1,0,0,0,1,1) The numbers correspond to my dataset. If the variables in my dataset are in the same group, there should be a 1 in my matching vector, and a 0 otherwise.

Find which rows have different values for a given column in Teradata SQL

寵の児 提交于 2019-11-28 07:25:34
I am trying to compare two addresses from the same ID to see whether they match. For example: Id Adress Code Address 1 1 123 Main 1 2 123 Main 2 1 456 Wall 2 2 456 Wall 3 1 789 Right 3 2 100 Left I'm just trying to figure out whether the address for each ID matches. So in this case I want to return just ID 3 as having a different address for Address Code 1 and 2. Join the table with itself and give it two different aliases ( A and B in the following example). This allows to compare different rows of the same table. SELECT DISTINCT A.Id FROM Address A INNER JOIN Address B ON A.Id = B.Id AND A.

select columns based on multiple strings with dplyr contains()

[亡魂溺海] 提交于 2019-11-28 05:45:22
I want to select multiple columns based on their names with a regex expression. I am trying to do it with the piping syntax of the dplyr package. I checked the other topics, but only found answers about a single string. With base R: library(dplyr) mtcars[grepl('m|ar', names(mtcars))] ### mpg am gear carb ### Mazda RX4 21.0 1 4 4 ### Mazda RX4 Wag 21.0 1 4 4 However it doesn't work with the select/contains way: mtcars %>% select(contains('m|ar')) ### data frame with 0 columns and 32 rows What's wrong? You can use matches mtcars %>% select(matches('m|ar')) %>% head(2) # mpg am gear carb #Mazda

“No matching function call” in constructor

主宰稳场 提交于 2019-11-27 23:52:40
问题 This is the constructor declaration that I have in my "solver.h" file. Solver(const Board &board_c, int max_moves_c); When trying to compile I get the following error... solver.cpp: In constructor 'Solver::Solver(const Board&, int)': solver.cpp:6:55: error: no matching function for call to 'Board::Board()' Solver::Solver(const Board &board_c, int max_moves_c) And then it lists the candidates which are the Board constructors. I'm not sure what I'm doing wrong as I see no reason why I should be

How can I extract a string between matching braces in Perl?

你离开我真会死。 提交于 2019-11-27 23:04:35
My input file is as below : HEADER {ABC|*|DEF {GHI 0 1 0} {{Points {}}}} {ABC|*|DEF {GHI 0 2 0} {{Points {}}}} {ABC|*|XYZ:abc:def {GHI 0 22 0} {{Points {{F1 1.1} {F2 1.2} {F3 1.3} {F4 1.4}}}}} {ABC|*|XYZ:ghi:jkl {JKL 0 372 0} {{Points {}}}} {ABC|*|XYZ:mno:pqr {GHI 0 34 0} {{Points {}}}} { ABC|*|XYZ:abc:pqr {GHI 0 68 0} {{Points {{F1 11.11} {F2 12.10} {F3 14.11} {F4 16.23}}}} } TRAILER I want to extract the file into an array as below : $array[0] = "{ABC|*|DEF {GHI 0 1 0} {{Points {}}}}" $array[1] = "{ABC|*|DEF {GHI 0 2 0} {{Points {}}}}" $array[2] = "{ABC|*|XYZ:abc:def {GHI 0 22 0} {{Points {

String Pattern Matching In Java

你说的曾经没有我的故事 提交于 2019-11-27 19:08:05
I want to search for a given string pattern in an input sting. For Eg. String URL = "https://localhost:8080/sbs/01.00/sip/dreamworks/v/01.00/cui/print/$fwVer/{$fwVer}/$lang/en/$model/{$model}/$region/us/$imageBg/{$imageBg}/$imageH/{$imageH}/$imageSz/{$imageSz}/$imageW/{$imageW}/movie/Kung_Fu_Panda_two/categories/3D_Pix/item/{item}/_back/2?$uniqueID={$uniqueID}" Now I need to search whether the string URL contains " /{item}/ ". Please help me. This is an example. Actually I need is check whether the URL contains a string matching "/{a-zA-Z0-9}/" You can use the Pattern class for this. If you

how to match dna sequence pattern

帅比萌擦擦* 提交于 2019-11-27 12:25:20
问题 I am getting a trouble finding an approach to solve this problem. Input-output sequences are as follows : **input1 :** aaagctgctagag **output1 :** a3gct2ag2 **input2 :** aaaaaaagctaagctaag **output2 :** a6agcta2ag Input nsequence can be of 10^6 characters and largest continuous patterns will be considered. For example for input2 "agctaagcta" output will not be "agcta2gcta" but it will be "agcta2". Any help appreciated. 回答1: Explanation of the algorithm: Having a sequence S with symbols s(1),

Can a range be matched in Scala?

青春壹個敷衍的年華 提交于 2019-11-27 11:26:58
问题 Is it possible to match a range of values in Scala? For example: val t = 5 val m = t match { 0 until 10 => true _ => false } m would be true if t was between 0 and 10, but false otherwise. This little bit doesn't work of course, but is there any way to achieve something like it? 回答1: Guard using Range : val m = t match { case x if 0 until 10 contains x => true case _ => false } 回答2: You can use guards: val m = t match { case x if (0 <= x && x < 10) => true case _ => false } 回答3: Here's