Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I have the following text already solved in R.
Do anyone know how to write it in Ruby?
text <- 'have a nice day, #hello, mr burs'
x <- gsub('.*(#\\w+).*', '\\1', text)
x
[1] "#hello"
Thanks!!
s = 'have a nice day, #hello, mr burs'
s =~ /.*(#\w+).*/ # match
$~[1] # this will return "#hello"
# $~ means "the last regexp match", a `MatchData` instance. And we can get matched group by index.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I have a text classification task for which I am trying to extract most significant verb from the text corpus.
For eg:
Text="Mailing the meeting notes" : Significant verb = Mail
Text="Call to set up meeting." : Significant verb Call.
How do I figure which is the most important verb?
library(udpipe)
x <- udpipe(c("Mailing the meeting notes", "Call to set up meeting."), "english-ewt")
subset(x, upos %in% c("VERB"))
and next think of how you would define significant
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 4 years ago.
Improve this question
Currently in R, with data.table, I have the following column:
jamesmann#yahoo.com
bill.free#yahoo.com
computer.trader#yahoo.com
j*****n#gmail.com
which are factors. I would like to parse the above so that I can get the first and last letters of the username before the # symbol.
So for the above I'd like to get:
jn
be
cr
jn
I deal with some asterisked usernames so I added it in too. Is there a simple way to do this? Any thoughts would be greatly appreciated.
Match the following pattern to the strings and replace it with the capture groups:
sub("(.).*(.)#.*", "\\1\\2", s)
## [1] "jn" "be" "cr" "jn"
Note
The input strings in reproducible form is:
s <- c("jamesmann#yahoo.com", "bill.free#yahoo.com", "computer.trader#yahoo.com",
"j*****n#gmail.com")
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I am trying to write this (SAS) comand in R. x is a variable with this specific format: j61915035t
x1 = trim(upcase(substr(x,1,1)));
I really appreciate what you are doing in this site!
You want to remove leading/trailing blanks from a character string that is the uppercase first letter of the string x. So this should do it.
library(stringr)
x1 = str_trim(str_to_upper(str_sub(x,1,1)))
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have an input text
inputQ <- "What can I do ..my baby has rash all over. Suggest good rash cream"
I have a list of terms
terms <- c("diaper","cloth diaper","rash pants","rash","baby wipes","rash cream")
I wish to exact match one of the terms and return it as well
I tried using for loop, but is there a better method
Result should be
rash cream
stored in matchedTerm
You can try to get all the matches, then check for the one with the biggest number of characters:
wh_match <- names(unlist(sapply(terms, grep, inputQ)))
wh_match[which.max(nchar(wh_match))]
# [1] "rash cream"
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have a vector which is the dimnames of another object (let's call it obj) in R:
"I(PT(z))" "trt" "I(PT(z)):trt"
I am not sure how many spaces are there in this output. Now I want to have a resultant vector of "I(PT(z))"+"trt"+"I(PT(z)):trt", i.e., replace the space with "+" signs. The tricky part here is that, length(obj)=3, and obj[[1]] gives "I(PT(z))", and so on. Is there a convenient way to do the concatenation? Thanks.
x <- c("I(PT(z))", "trt", "I(PT(z)):trt")
x
[1] "I(PT(z))" "trt" "I(PT(z)):trt"
paste(x, collapse="+")
[1] "I(PT(z))+trt+I(PT(z)):trt"