stringr

how can I extract numbers from a string in R?

家住魔仙堡 提交于 2021-02-05 06:55:27
问题 names(score) [1] "(Intercept)" "aado2_calc(20,180]" "aado2_calc(360,460]" [4] "aado2_calc(460,629]" "albumin[1,1.8]" "albumin(1.8,2.2]" [7] "albumin(2.2,2.8]" "aniongap(15,18]" "aniongap(18,20]" [10] "aniongap(20,22]" "aniongap(22,25]" "aniongap(25,49]" I want to extract the two numbers within parenthesis (numbers outside the parenthesis are not needed) and there are "(" or "[". the first number will be assigned to an object "low" and the second to "high". 回答1: scorenames <- c( "(Intercept)"

Extract Last Upper cases from a string [duplicate]

淺唱寂寞╮ 提交于 2021-01-29 09:04:02
问题 This question already has answers here : Extract the last word between | | (5 answers) Closed 2 years ago . I am practicing with regular expressions in R. I would like to extract the last occurrence of two upper case letters. I tried >str_extract("kjhdjkaYY,","[:upper:][:upper:]") [1] "YY" And it works perfectly fine. What if I would like to extract the last occurrence of such pattern. Example: function("kKKjhdjkaYY,") [1] "YY" Thank you for your help 回答1: We can use stri_extract_last_regex

Is there a way to use for loops within dplyr to reduce the number of str_detect terms needed?

妖精的绣舞 提交于 2021-01-27 21:11:52
问题 I'm currently working on a project, and I'm looking at classifying about a hundred thousand strings, based on their content. The goal of this code is to identify if a string matches, classify them to a particular bucket, then to save the end result to a csv. No code contains more than one matching string. I realise that after a certain point my code gets a little unreadable - mostly because if I have to change one of say, two hundred str_detect functions with the same format, I then have to

case_when with partial string match and contains()

自古美人都是妖i 提交于 2021-01-27 18:09:01
问题 I'm working with a dataset that has many columns called status1, status2, etc. Within those columns, it says if someone is exempt, complete, registered, etc. Unfortunately, the exempt inputs are not consistent; here's a sample: library(dplyr) problem <- tibble(person = c("Corey", "Sibley", "Justin", "Ruth"), status1 = c("7EXEMPT", "Completed", "Completed", "Pending"), status2 = c("exempt", "Completed", "Completed", "Pending"), status3 = c("EXEMPTED", "Completed", "Completed", "ExempT - 14"))

Negative lookahead in regex to exclude percentage (%) in R

99封情书 提交于 2021-01-27 18:00:30
问题 I wish to extract numbers with any decimals (at least one number both sides of the decimal), but not patterns followed by percentages. Therefore, I believe I need a negative lookahead (so it can see if the number is followed by a percentage sign). For clarity, I would want to extract "123.123" , but would not like to extract "123.123%" I have tried a dozen syntax arrangements but cannot find the one that works. This successfully extracts the decimal pattern. c("123.123%", "123.123") %>% str

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

transitions in a sequence

元气小坏坏 提交于 2020-12-26 12:05:02
问题 I have a dataset and I would like to the probability of transition. So I have three alphabets like this (13 states) which are possible: CCE CRE DEE FOE GOE ICE ISE MEE PCE PRE PSE RLE WAE For example, # A<- c('A-A-A-B', 'A-A-A-A', 'A-B-C-D', 'A-A') A<- c('CCE-CRE-DEE-DEE', 'FOE-FOE-GOE-GOE-GOE-ISE', 'ISE-PCE', 'ISE') library('stringr') B<- str_count(A, "-") df<- data.frame(A, B) I would like to get the transition among the letters, for example in the total transitions (how many are to other

transitions in a sequence

强颜欢笑 提交于 2020-12-26 12:04:58
问题 I have a dataset and I would like to the probability of transition. So I have three alphabets like this (13 states) which are possible: CCE CRE DEE FOE GOE ICE ISE MEE PCE PRE PSE RLE WAE For example, # A<- c('A-A-A-B', 'A-A-A-A', 'A-B-C-D', 'A-A') A<- c('CCE-CRE-DEE-DEE', 'FOE-FOE-GOE-GOE-GOE-ISE', 'ISE-PCE', 'ISE') library('stringr') B<- str_count(A, "-") df<- data.frame(A, B) I would like to get the transition among the letters, for example in the total transitions (how many are to other