grepl

R filter rows based on multiple partial strings applied to multiple columns

女生的网名这么多〃 提交于 2021-02-16 14:11:15
问题 Sample of dataset: diag01 <- as.factor(c("S7211","J47","J47","K729","M2445","Z509","Z488","R13","L893","N318","L0311","S510","A047","D649")) diag02 <- as.factor(c("K590","D761","J961","T501","M8580","R268","T831","G8240","B9688","G550","E162","T8902","E86","I849")) diag03 <- as.factor(c("F058","M0820","E877","E86","G712","R32","A408","E888","G8220","C794","T68","L0310","M1094","D469")) diag04 <- as.factor(c("E86","C845","R790","I420","G4732","R600","L893","R509","T913","C795","M8412","G8212",

extract part of word into a field from a long string using R

旧巷老猫 提交于 2021-02-12 11:41:18
问题 I have a single long string variable with 3 obs. I was trying to create a field prob to extract the specific string from the long string. the code and message is below. data aa: "The probability of being a carrier is 0.0002422359 " " an BRCA1 carrier 0.0001061067 " " an BRCA2 carrier 0.00013612 " enter code here aa$prob <- ifelse(grepl("The probability of being a carrier is", xx)==TRUE, word(aa, 8, 8), ifelse(grepl("BRCA", xx)==TRUE, word(aa, 5, 5), NA)) Warning message: In aa$prob <- ifelse

extract part of word into a field from a long string using R

人盡茶涼 提交于 2021-02-12 11:40:11
问题 I have a single long string variable with 3 obs. I was trying to create a field prob to extract the specific string from the long string. the code and message is below. data aa: "The probability of being a carrier is 0.0002422359 " " an BRCA1 carrier 0.0001061067 " " an BRCA2 carrier 0.00013612 " enter code here aa$prob <- ifelse(grepl("The probability of being a carrier is", xx)==TRUE, word(aa, 8, 8), ifelse(grepl("BRCA", xx)==TRUE, word(aa, 5, 5), NA)) Warning message: In aa$prob <- ifelse

Grepl group of strings and count frequency of all using R

一个人想着一个人 提交于 2021-02-11 12:08:56
问题 I have a column of 50k rows of tweets named text from a csv file (the tweets consists of sentences, phrases etc). I'm trying to count frequency of several words in that column. Is there an easier way to do it vs what I'm doing below? # Reading my file tweets <- read.csv('coffee.csv', header=TRUE) # Doing a grepl per word (This is hard because I need to look for many words one by one) coffee <- grepl("coffee", text$tweets, ignore.case=TRUE) mugs <- grepl("mugs", text$tweets, ignore.case=TRUE)

Grepl group of strings and count frequency of all using R

一世执手 提交于 2021-02-11 12:08:23
问题 I have a column of 50k rows of tweets named text from a csv file (the tweets consists of sentences, phrases etc). I'm trying to count frequency of several words in that column. Is there an easier way to do it vs what I'm doing below? # Reading my file tweets <- read.csv('coffee.csv', header=TRUE) # Doing a grepl per word (This is hard because I need to look for many words one by one) coffee <- grepl("coffee", text$tweets, ignore.case=TRUE) mugs <- grepl("mugs", text$tweets, ignore.case=TRUE)

What's the difference between the str_detect function in stringer and grepl and grep? [closed]

大憨熊 提交于 2021-01-01 14:54:39
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 1 year ago . Improve this question I'm starting to do a lot of string matching in my work and I'm curious as to what the differences between the three functions are, and in what situations someone would use one over the other. 回答1: stringr is a "A consistent, simple and easy to use set of

What's the difference between the str_detect function in stringer and grepl and grep? [closed]

非 Y 不嫁゛ 提交于 2021-01-01 14:36:47
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 1 year ago . Improve this question I'm starting to do a lot of string matching in my work and I'm curious as to what the differences between the three functions are, and in what situations someone would use one over the other. 回答1: stringr is a "A consistent, simple and easy to use set of

What's the difference between the str_detect function in stringer and grepl and grep? [closed]

只愿长相守 提交于 2021-01-01 14:34:40
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 1 year ago . Improve this question I'm starting to do a lot of string matching in my work and I'm curious as to what the differences between the three functions are, and in what situations someone would use one over the other. 回答1: stringr is a "A consistent, simple and easy to use set of

r check if string contains special characters

笑着哭i 提交于 2020-08-27 21:51:21
问题 I am checking if a string contains any special characters. This is what I have, and its not working, if(grepl('^\\[:punct:]', val)) So if anybody can tell me what I am missing, that will be helpful. Special characters ~ ` ! @# $ % ^ & * | : ; , ." | 回答1: As @thelatemail pointed out in the comments you can use: grepl('[^[:punct:]]', val) which will result in TRUE or FALSE for each value in your vector. You can add sum() to the beginning of the statement to get the total number of these cases.

r check if string contains special characters

…衆ロ難τιáo~ 提交于 2020-08-27 21:50:44
问题 I am checking if a string contains any special characters. This is what I have, and its not working, if(grepl('^\\[:punct:]', val)) So if anybody can tell me what I am missing, that will be helpful. Special characters ~ ` ! @# $ % ^ & * | : ; , ." | 回答1: As @thelatemail pointed out in the comments you can use: grepl('[^[:punct:]]', val) which will result in TRUE or FALSE for each value in your vector. You can add sum() to the beginning of the statement to get the total number of these cases.