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"
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] ":"
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
"h
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
wrote:
> ?grepl
>
> Note that this function uses regular expressions, in which certain cha
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:
http://r.78
?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.
-
grepl
Michael
On Tue, Jun 12, 2012 at 8:51 AM, anjali 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:
> http://r.789695.n4.nabble.com/String-Manipulation-in-R-t
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.
__
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 man
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 (
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
what
On Fri, Aug 26, 2011 at 7:27 AM, Jeff Newmiller
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 * to make the repe
".*" 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: Basics: ##.#. ##.#. Live Go...
Live: OO
On Thu, Aug 25, 2011 at 9:51 PM, Lorenzo Cattarino
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 position of 2000
uot;number". The position of 2000 in the string might change.
thanks
Lorenzo
-Original 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 manipul
thanks
Lorenzo
-Original 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 f
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,
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]
nynumbers<-
Try this:
gsub(".*second number ", "", mytext)
On Thu, Aug 25, 2011 at 8:00 PM, Lorenzo Cattarino
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 first number
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
thi
On Sun, Jun 26, 2011 at 11:00 AM, Gabor Grothendieck
wrote:
> On Sun, 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 eleme
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
On Sun, 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 exam
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
elemen
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 du
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, Deni
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
PLEAS
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
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" "34564" "IJVEOJC" "3434"
Therefore there is decimal number in th
Just add '.' to the pattern specifier:
> MyString <- "ABCFR34564IJVEOJC3434.16ABC123.456KJHLKJH23452345AAA"
> # translate to the pattern sequences
> x <- chartr('ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.'
+ , '00111'
+ , MyString
+ )
> x.rl
On Sun, Feb 13, 2011 at 4:42 PM, Megh Dal 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" "34564"
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
+
On Sun, Feb 13, 2011 at 10:27 AM, Megh Dal 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 separate ou
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
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"
See
?Encoding and ?iconv:
iconv("\xc1d\xe1m", from = '', to = 'latin1')
On Sat, May 8, 2010 at 11:05 AM, Webby wrote:
>
> Dear community,
>
> I have a problem with a string conversion:
>
> > text
> [1] "" "and""\xc1d\xe1m"
> [4] "graphical" "interf
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] "
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 o
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
On Fri, Feb 5, 2010 at 9:29 AM, jim holtman 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 <-
c("1234567.z3.abcdef-gh.12","1234567.
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" "z3""abcdef-gh" "12"
[[2]]
[1] "1234567" "z3""abcdef-gh" "12"
[[3]]
[1] "1234567" "z3""abcdef-gh" "12"
> y
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 stri
42 matches
Mail list logo