matching

R returning partial matching of row names

独自空忆成欢 提交于 2021-02-18 22:37:29
问题 I've run into the following issue vec <- c("a11","b21","c31") df <- data.frame(a = c(0,0,0), b = c(1,1,1), row.names = vec) df["a",] returns df["a",] a b a11 0 1 However, "a" %in% vec and "a" %in% rownames(df) both return False R is allowing for partial matching of the string when using letter followed by numbers for row names. I have replicated this on R v3.2.2 and R v3.2.1. Even df[["a",1,exact=T]] returns 0 Is there anything I can set such that R does not allow this partial matching? 回答1:

How to use regex for matching multiple words

拜拜、爱过 提交于 2021-02-16 18:13:19
问题 How can I use regex to match multiple words in java? For example, the addAction("word") and intentFilter("word") at the same time for matching? I tried: string REGEX ="[\\baddAction\\b|\\bintentFilter\\b]\\s*\([\"]\\s*\\bword\\b\\s*[\"]\)"; Could someone tell me what's wrong with this format and how can I fix it? 回答1: You are trying to use alternative lists in a regex, but instead you are using a character class ( "[\\baddAction\\b|\\bintentFilter\\b] ). With a character class, all characters

Read a file in clojure and ignore the first line?

偶尔善良 提交于 2021-02-09 11:57:43
问题 Using code from this answer, I have (defn repeat-image [n string] (println (apply str (repeat n string)))) (defn tile-image-across [x filename] (with-open [rdr (reader filename)] (doseq [line (line-seq rdr)] (repeat-image x line)))) ...to tile an ascii image horizontally. Now, how would I be able to "ignore" the first line? The reason I'm doing this is each image has the coordinates (for example "20 63") as the first line, and I don't need the line. I tried some ways (keeping an index,

extracting substring using regex in sas

蓝咒 提交于 2021-01-29 12:09:30
问题 I have a string like this: dfjkldjfdsldfkdslfkd dfkdjd/FR018/HAHDFKDLFDAFHDKFJL/ABCD//NAME/I WANT TO EXTRACT THIS/JJJJ//NAME/blah blah blah in this string, I want to be able to pull the string I WANT TO EXTRACT THIS . In other words, I want to extract everything that follows /ABCD//NAME/ and before /JJJJ . how can I write this using regular expressions? thanks 回答1: I am not familiar with SAS, but from the documentation it seems like you can do: re = prxparse('/\/ABCD\/\/NAME\/(.*?)\/(.*?)\

java regexp match morse code

自闭症网瘾萝莉.ら 提交于 2021-01-27 10:58:30
问题 I'm trying to test if the Morse code is legal. public static boolean isMorseCode( String code ){ return code.trim().matches("[+.|+\s|+-]"); } The Morse code line can begin with a . (known as Dit) and a - (known as Dah). It can have spaces in the line. 1 space between two specific codes like .- -. in this case the sum of codes which are only separated by one white space is a word. But it can also have 3 white spaces and then a new word begins. I'm using trim to exclude the fact that there

How to set values based on a list in Pandas (python)

余生颓废 提交于 2021-01-07 07:49:33
问题 I have a maybe a hopefully easy question that I wasn't able to find an answer on stack. I have a a dataframe (df) and I want to set a value (some_value) if a value from the column 'month' is in a list (some_list). e.g. df[df['month'].isin(some_list)] = some_value It's barfing up an AttributeError: 'int' object has no attribute 'view'. Any helpful direction would be awesome. [edit]: some_list = [4,5,6,7] some_value = 100 df.month is a value from 1 - 12 df.columns = ['datetime','weekday','hour'

How to set values based on a list in Pandas (python)

我们两清 提交于 2021-01-07 07:49:27
问题 I have a maybe a hopefully easy question that I wasn't able to find an answer on stack. I have a a dataframe (df) and I want to set a value (some_value) if a value from the column 'month' is in a list (some_list). e.g. df[df['month'].isin(some_list)] = some_value It's barfing up an AttributeError: 'int' object has no attribute 'view'. Any helpful direction would be awesome. [edit]: some_list = [4,5,6,7] some_value = 100 df.month is a value from 1 - 12 df.columns = ['datetime','weekday','hour'

How to set values based on a list in Pandas (python)

两盒软妹~` 提交于 2021-01-07 07:49:18
问题 I have a maybe a hopefully easy question that I wasn't able to find an answer on stack. I have a a dataframe (df) and I want to set a value (some_value) if a value from the column 'month' is in a list (some_list). e.g. df[df['month'].isin(some_list)] = some_value It's barfing up an AttributeError: 'int' object has no attribute 'view'. Any helpful direction would be awesome. [edit]: some_list = [4,5,6,7] some_value = 100 df.month is a value from 1 - 12 df.columns = ['datetime','weekday','hour'

Matching based on different independent tables using data.table in R

|▌冷眼眸甩不掉的悲伤 提交于 2021-01-01 09:09:06
问题 I would like to match multiple conditions from independent data tables onto my main data table. How can I do this using the data.table package? What would be the most efficient/fastest way? I have a mock example, with some mock conditions here to illustrate my question: main_data <- data.frame( pnum = c(1,2,3,4,5,6,7,8,9,10), age = c(24,35,43,34,55,24,36,43,34,54), gender = c("f","m","f","f","m","f","m","f","f","m")) data_1 <- data.frame( pnum = c(1,4,5,8,9), value_data_1 = c(1, 2, 1, 1, 1),