[R] String manipulation

2014-12-08 Thread Gang Chen
I want to do the following: if a string does not contain a colon (:), no change is needed; if it contains one or more colons, break the string into multiple strings using the colon as a separator. For example, happy: becomes happy : :sad turns to : sad and happy:sad changes to happy : sad

Re: [R] String manipulation

2014-12-08 Thread William Dunlap
strsplit(split=:) does almost what you want, but it omits the colons from the output. You can use perl zero-length look-ahead and look-behind operators in the split argument to get the colons as well: strsplit(c(:sad, happy:, happy:sad), split=(?=:)|(?=:), perl=TRUE) [[1]] [1] : sad [[2]]

Re: [R] String manipulation

2014-12-08 Thread William Dunlap
Actually, the zero-length look-ahead expression is enough to get the job done: strsplit(c(:sad, happy:, happy:sad, :happy:sad:subdued:), split=(?=:), perl=TRUE) [[1]] [1] : sad [[2]] [1] happy : [[3]] [1] happy : sad [[4]] [1] : happy : sad : subdued : Bill

[R] String Manipulation in R

2012-06-12 Thread anjali
Hi , Is there any inbuilt functions to check whether a substring is present in a string and give the result as boolean Thanks -- View this message in context: http://r.789695.n4.nabble.com/String-Manipulation-in-R-tp4633104.html Sent from the R help mailing list archive at Nabble.com.

Re: [R] String Manipulation in R

2012-06-12 Thread R. Michael Weylandt
grepl Michael On Tue, Jun 12, 2012 at 8:51 AM, anjali jeevi...@gmail.com wrote: Hi , Is there any inbuilt functions  to check whether a substring is present in a string and give the result as boolean Thanks -- View this message in context:

Re: [R] String Manipulation in R

2012-06-12 Thread Jeff Newmiller
?grepl Note that this function uses regular expressions, in which certain characters have special meanings, so depending on what string you are looking for you may have to know something about regex patterns to get it to work.

Re: [R] String Manipulation in R

2012-06-12 Thread Rui Barradas
Hello, Yes, there is. See ?grepl or help('grepl'). Hope this helps, Rui Barradas Em 12-06-2012 14:51, anjali escreveu: Hi , Is there any inbuilt functions to check whether a substring is present in a string and give the result as boolean Thanks -- View this message in context:

Re: [R] String Manipulation in R

2012-06-12 Thread Greg Snow
Or use 'fixed=TRUE' as an argument to grepl to avoid the regular expression matching (but learning regular expressions will be a useful tool in the long run). On Tue, Jun 12, 2012 at 9:15 AM, Jeff Newmiller jdnew...@dcn.davis.ca.us wrote: ?grepl Note that this function uses regular

Re: [R] String manipulation with regexpr, got to be a better way

2011-09-30 Thread Eik Vettorazzi
Hi Chris, why not using routines for dates dates - c(09/10/2003, 10/22/2005) format(strptime(dates,format=%m/%d/%Y),%Y) or take just the last 4 chars from dates gsub(.*([0-9]{4})$,\\1,dates) cheers Am 29.09.2011 16:23, schrieb Chris Conner: Help-Rs, I'm doing some string manipulation in a

[R] String manipulation with regexpr, got to be a better way

2011-09-29 Thread Chris Conner
Help-Rs,   I'm doing some string manipulation in a file where I converted a string date in mm/dd/ format and returned the date .   I've used regexpr (hat tip to Gabor G for a very nice earlier post on this function) in steps (I've un-nested the code and provided it and an example of

Re: [R] String manipulation with regexpr, got to be a better way

2011-09-29 Thread Jean V Adams
Chris Conner wrote on 09/29/2011 09:23:02 AM: Help-Rs, I'm doing some string manipulation in a file where I converted a string date in mm/dd/ format and returned the date . I've used regexpr (hat tip to Gabor G for a very nice earlier post on this function) in steps (I've

Re: [R] string manipulation

2011-08-26 Thread Janko Thyson
Message- From: Steven Kennedy [mailto:stevenkennedy2...@gmail.com] Sent: Friday, 26 August 2011 11:31 AM To: Henrique Dallazuanna Cc: Lorenzo Cattarino; r-help@r-project.org Subject: Re: [R] string manipulation You can split your string, and then only take the first 4 digits after that (this is only

Re: [R] string manipulation

2011-08-26 Thread Gabor Grothendieck
On Thu, Aug 25, 2011 at 9:51 PM, Lorenzo Cattarino l.cattar...@uq.edu.au wrote: Apologies for confusion. What I meant was the following: mytext - I want the number 2000, not the number two thousand and the problem is to select 2000 as the first four digits after the word number. The

Re: [R] string manipulation

2011-08-26 Thread Jeff Newmiller
.* is greedy... might want regex number[^0-9]*([0-9] {4}) to avoid getting 1999 from I want the number 2000, not the number 1999. --- Jeff Newmiller The . . Go Live... DCN:jdnew...@dcn.davis.ca.us Basics: ##.#. ##.#.

Re: [R] string manipulation

2011-08-26 Thread Gabor Grothendieck
On Fri, Aug 26, 2011 at 7:27 AM, Jeff Newmiller jdnew...@dcn.davis.ca.us wrote: .* is greedy... might want regex number[^0-9]*([0-9] {4}) to avoid getting 1999 from I want the number 2000, not the number 1999. If such inputs are possible we could also do this where we have added a ? after the *

[R] string manipulation

2011-08-25 Thread Lorenzo Cattarino
I R-users, I am trying to find the way to manipulate a character string to select a 4 digit number after some specific word/s. Example: mytext - I do not want the first number 1234, but the second number 5678 Is there any function that allows you to select a certain number of digits (in this

Re: [R] string manipulation

2011-08-25 Thread Henrique Dallazuanna
Try this: gsub(.*second number , , mytext) On Thu, Aug 25, 2011 at 8:00 PM, Lorenzo Cattarino l.cattar...@uq.edu.au wrote: I R-users, I am trying to find the way to manipulate a character string to select a 4 digit number after some specific word/s. Example: mytext - I do not want the

Re: [R] string manipulation

2011-08-25 Thread Steven Kennedy
You can split your string, and then only take the first 4 digits after that (this is only an improvement if your numbers might not be at the end of mytext): mytext - I do not want the first number 1234, but the second number 5678 sstr-strsplit(mytext,split=second number )[[1]][2]

Re: [R] string manipulation

2011-08-25 Thread jim holtman
To be on the safe side in case there are other characters at the end of the string, use: mytext - I do not want the first number 1234, but the second number 5678sadfsadffdsa # make sure you get 4 digits sub(^.*second number[^[0-9]]*([0-9]{4}).*, \\1, mytext) [1] 5678 On Thu, Aug 25, 2011

Re: [R] string manipulation

2011-08-25 Thread Lorenzo Cattarino
- From: Steven Kennedy [mailto:stevenkennedy2...@gmail.com] Sent: Friday, 26 August 2011 11:31 AM To: Henrique Dallazuanna Cc: Lorenzo Cattarino; r-help@r-project.org Subject: Re: [R] string manipulation You can split your string, and then only take the first 4 digits after that (this is only

[R] String manipulation

2011-06-26 Thread Megh Dal
Dear all, I have following kind of character vector: Vec - c(344426, dwjjsgcj, 123sgdc, aagha123, sdh343asgh, 123jhd51) Now I want to split each element of this vector according to numeric and string element. For example in the 1st element of that vector, there is no string element. Therefore

Re: [R] String manipulation

2011-06-26 Thread Gabor Grothendieck
On Sun, Jun 26, 2011 at 10:54 AM, Megh Dal megh700...@yahoo.com wrote: Dear all, I have following kind of character vector: Vec - c(344426, dwjjsgcj, 123sgdc, aagha123, sdh343asgh, 123jhd51) Now I want to split each element of this vector according to numeric and string element. For

Re: [R] String manipulation

2011-06-26 Thread David Winsemius
On Jun 26, 2011, at 10:54 AM, Megh Dal wrote: Dear all, I have following kind of character vector: Vec - c(344426, dwjjsgcj, 123sgdc, aagha123, sdh343asgh, 123jhd51) Now I want to split each element of this vector according to numeric and string element. For example in the 1st element

Re: [R] String manipulation

2011-06-26 Thread Gabor Grothendieck
On Sun, Jun 26, 2011 at 11:00 AM, Gabor Grothendieck ggrothendi...@gmail.com wrote: On Sun, Jun 26, 2011 at 10:54 AM, Megh Dal megh700...@yahoo.com wrote: Dear all, I have following kind of character vector: Vec - c(344426, dwjjsgcj, 123sgdc, aagha123, sdh343asgh, 123jhd51) Now I want to

[R] String manipulation

2011-03-08 Thread Denis Kazakiewicz
Dear [R] people Could you please help with following How to convert a vector 'ac','ac','c','ac','ac','c' into a single string 'ac2_c_ac2_c' Thank you in advance __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help

Re: [R] String manipulation

2011-03-08 Thread jim holtman
Try this: x - c('ac','ac','c','ac','ac','c') rle(x) Run Length Encoding lengths: int [1:4] 2 1 2 1 values : chr [1:4] ac c ac c z - rle(x) paste(z$values, ifelse(z$lengths == 1, '', z$lengths), collapse='_', sep = '') [1] ac2_c_ac2_c On Tue, Mar 8, 2011 at 6:33 PM, Denis Kazakiewicz

Re: [R] String manipulation

2011-03-08 Thread Jannis
Dennis, If I understand you correctly (your example does not point unambiguously to one unique solution...) you could try: dummy- c('ac','ac','c','ac','ac','c') dummy.rle-rle(dummy) result - paste(dummy.rle$values,dummy.rle$lengths,collapse='_',sep='') You may need to remove the '1' in

Re: [R] String manipulation

2011-02-16 Thread rex.dwyer
Grothendieck Cc: r-help@r-project.org Subject: Re: [R] String manipulation Hi Gabor, thanks (and Jim as well) for your suggestion. However this is not working properly for following string: MyString - ABCFR34564IJVEOJC3434.36453 strapply(MyString, (\\D+)(\\d+)(\\D+)(\\d file://d+)(//d+)(//D+)(//d

[R] String manipulation

2011-02-13 Thread Megh Dal
Please consider following string: MyString - ABCFR34564IJVEOJC3434 Here you see that, there are 4 groups in above string. 1st and 3rd groups are for english letters and 2nd and 4th for numeric. Given a string, how can I separate out those 4 groups? Thanks for your time [[alternative

Re: [R] String manipulation

2011-02-13 Thread Gabor Grothendieck
On Sun, Feb 13, 2011 at 10:27 AM, Megh Dal megh700...@gmail.com wrote: Please consider following string: MyString - ABCFR34564IJVEOJC3434 Here you see that, there are 4 groups in above string. 1st and 3rd groups are for english letters and 2nd and 4th for numeric. Given a string, how can I

Re: [R] String manipulation

2011-02-13 Thread jim holtman
If you have an indeterminate number of the patterns in the string, try the following: MyString - ABCFR34564IJVEOJC3434 # translate to the pattern sequences x - chartr('ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' + , '0011' + , MyString +

Re: [R] String manipulation

2011-02-13 Thread Gabor Grothendieck
On Sun, Feb 13, 2011 at 4:42 PM, Megh Dal megh700...@gmail.com wrote: Hi Gabor, thanks (and Jim as well) for your suggestion. However this is not working properly for following string: MyString - ABCFR34564IJVEOJC3434.36453 strapply(MyString, (\\D+)(\\d+)(\\D+)(\\d+), c)[[1]] [1] ABCFR  

Re: [R] String manipulation

2011-02-13 Thread jim holtman
Just add '.' to the pattern specifier: MyString - ABCFR34564IJVEOJC3434.16ABC123.456KJHLKJH23452345AAA # translate to the pattern sequences x - chartr('ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.' + , '00111' + , MyString + ) x.rle -

Re: [R] String manipulation

2011-02-13 Thread Megh Dal
Hi Gabor, thanks (and Jim as well) for your suggestion. However this is not working properly for following string: MyString - ABCFR34564IJVEOJC3434.36453 strapply(MyString, (\\D+)(\\d+)(\\D+)(\\d file://d+)(//d+)(//D+)(//d+), c)[[1]] [1] ABCFR 34564 IJVEOJC 3434 Therefore there is decimal

[R] String manipulation

2010-05-08 Thread Webby
Dear community, I have a problem with a string conversion: text [1]and\xc1d\xe1m [4] graphical interface MLP [7] Nagy networks Networks [10] neural Neural RBF [13] sod...@yahoo.com user

Re: [R] String manipulation

2010-05-08 Thread Henrique Dallazuanna
See ?Encoding and ?iconv: iconv(\xc1d\xe1m, from = '', to = 'latin1') On Sat, May 8, 2010 at 11:05 AM, Webby mailing-l...@gmx.net wrote: Dear community, I have a problem with a string conversion: text [1]and\xc1d\xe1m [4] graphical

Re: [R] String manipulation

2010-05-08 Thread David Winsemius
On May 8, 2010, at 10:05 AM, Webby wrote: Dear community, I have a problem with a string conversion: text [1]and\xc1d\xe1m [4] graphical interface MLP [7] Nagy networks Networks [10] neural Neural

[R] String Manipulation- Extract numerical and alphanumerical segment

2010-02-05 Thread Su C.
I am currently attempting to split a long list of strings (let's call it string.list) that is of the format: 1234567.z3.abcdef-gh.12 I have gotten it to: 1234567 z3 abcdef-gh 12 by use of the strsplit function. This leaves me with each element of string.list having a split string of the

Re: [R] String Manipulation- Extract numerical and alphanumerical segment

2010-02-05 Thread jim holtman
Does this help: x - c(1234567.z3.abcdef-gh.12,1234567.z3.abcdef-gh.12,1234567.z3.abcdef-gh.12) y - strsplit(x, '[.]') y [[1]] [1] 1234567 z3abcdef-gh 12 [[2]] [1] 1234567 z3abcdef-gh 12 [[3]] [1] 1234567 z3abcdef-gh 12 y.1 - sapply(y, '[[', 1) y.1 [1]

Re: [R] String Manipulation- Extract numerical and alphanumerical segment

2010-02-05 Thread hadley wickham
On Fri, Feb 5, 2010 at 9:29 AM, jim holtman jholt...@gmail.com wrote: Does this help: x - c(1234567.z3.abcdef-gh.12,1234567.z3.abcdef-gh.12,1234567.z3.abcdef-gh.12) y - strsplit(x, '[.]') Here's another way with the stringr package: library(stringr) x -

Re: [R] String Manipulation- Extract numerical and alphanumerical segment

2010-02-05 Thread Su C.
Yes, that was perfect! Thank you so much! Just to clarify, since I'm kind of new to string manipulation-- is that '[[' in the sapply function what is designating splits/elements within the string? So that's the part that says I want this particular element and the 1 or 2 or number is what

Re: [R] String Manipulation- Extract numerical and alphanumerical segment

2010-02-05 Thread jim holtman
The '[[' is just the index access to an object. type: ?'[[' to see the help page. Actually I should have used '[' in this case: sapply(y, '[', 1) [1] 1234567 1234567 1234567 is equivalent to: sapply(y, function(a) a[1]) [1] 1234567 1234567 1234567 So set a value based on the first