Re: [R] string concatenation

2020-11-05 Thread Jiefei Wang
Hi, Thanks for clarifying, there is no quote in the result. The quote in the output is just R's way to tell you that the variable got printed is a string. If you add quotes around a string, it will get printed like "\"Alice, Bob, Charles\"" I hope this helps. Best, Jiefei On Thu, Nov 5, 2020 a

Re: [R] string concatenation

2020-11-05 Thread Duncan Murdoch
On 05/11/2020 3:20 a.m., Edjabou Vincent wrote: Following John request, I am wondering if it is possible to get this result: Alice, Bob, Charles (without bracket ) I think you mean "without the quotes". Use noquote(): noquote(paste0(x,collapse = ", ")) will print without quotes. (Interna

Re: [R] string concatenation

2020-11-05 Thread Edjabou Vincent
Following John request, I am wondering if it is possible to get this result: Alice, Bob, Charles (without bracket ) Thank you for your help Med venlig hilsen/ Best regards Vincent Edjabou Mobile: +45 31 95 99 33 linkedin.com/vincent O

Re: [R] string concatenation

2020-11-04 Thread Jiefei Wang
Hi John, Try paste0(x,collapse = ", ") Best, Jiefei On Thu, Nov 5, 2020 at 1:16 PM John wrote: > Hi, > > I have a sequence of characters: > > x <- c("Alice", "Bob", "Charles") > > How can I produce the following results: > > "Alice, Bob, Charles" > > ? > > paste? merge? > > Thank you very much

[R] string concatenation

2020-11-04 Thread John
Hi, I have a sequence of characters: x <- c("Alice", "Bob", "Charles") How can I produce the following results: "Alice, Bob, Charles" ? paste? merge? Thank you very much! [[alternative HTML version deleted]] __ R-help@r-project.org mailin

Re: [R] String replace

2019-04-03 Thread Ivan Krylov
On Wed, 3 Apr 2019 15:01:37 +0100 Graham Leask via R-help wrote: Suppose that `BHC$Date` contains a string "M_24". You do: > BHC <-BHC %>% mutate ( Date = stringr :: str_replace ( Date , "M_2" , > "01-04-2017")) before you have a chance to do: > BHC <-BHC %>% mutate ( Date = stringr :: str_re

Re: [R] String replace

2019-04-03 Thread Sarah Goslee
Try reversing the order, or extending the to-replace bit. "M_1" is finding and replacing "M_10", "M_11", etc. "M_2" is finding and replacing "M_20", "M_21", etc. So M_14 becomes "01-03-20174" In the future, a toy dataset would help with the reproducible example aspect, and make your question eas

[R] String replace

2019-04-03 Thread Graham Leask via R-help
I’m attempting to replace a string variable that normally works fine. However when trying to do this with a string in the form of a date the output becomes corrupted. See below: BHC <-BHC %>% mutate ( Date = stringr :: str_replace ( Date , "M_1" , "01-03-2017")) BHC <-BHC %>% mutate ( Date =

Re: [R] string pattern matching

2017-03-23 Thread Joe Ceradini
Oh, I see the utility of that now. Definitely will be using "term.labels" (which I was not aware of). Thanks! On Thu, Mar 23, 2017 at 9:48 AM, William Dunlap wrote: > If you are trying to see if one model nested in another then I think > looking at the 'term.labels' attribute of terms(formula) i

Re: [R] string pattern matching

2017-03-23 Thread William Dunlap via R-help
If you are trying to see if one model nested in another then I think looking at the 'term.labels' attribute of terms(formula) is the way to go. Most formula-based modelling functions store the output of terms(formula) in their output and many supply a method for the terms function that extracts th

Re: [R] string pattern matching

2017-03-23 Thread Joe Ceradini
Thanks for the additional response, Bill. I did not want to bog down the question with the full context of the function. Briefly, given a set of nested and non-nested regression models, I want to compare AIC (bigger model - smaller model) and do an LRT for all the nested models that differ by a sin

Re: [R] string pattern matching

2017-03-22 Thread William Dunlap via R-help
You did not describe the goal of your pattern matching. Were you trying to match any string that could be interpreted as an R expression containing X1 and X3 as additive terms? If so, you could turn the string into a one-sided formula and use the terms() function. E.g., f <- function(string) {

Re: [R] string pattern matching

2017-03-22 Thread Joe Ceradini
Wow. Thanks to everyone (Jim, Ng Bo Lin, Bert, David, and Ulrik) for all the quick and helpful responses. They have given me a better understanding of regular expressions, and certainly answered my question. Joe On Wed, Mar 22, 2017 at 12:22 AM, Ulrik Stervbo wrote: > Hi Joe, > > you could also

Re: [R] string pattern matching

2017-03-21 Thread Ulrik Stervbo
Hi Joe, you could also rethink your pattern: grep("x1 \\+ x2", test, value = TRUE) grep("x1 \\+ x", test, value = TRUE) grep("x1 \\+ x[0-9]", test, value = TRUE) HTH Ulrik On Wed, 22 Mar 2017 at 02:10 Jim Lemon wrote: > Hi Joe, > This may help you: > > test <- c("x1", "x2", "x3", "x1 + x2 +

Re: [R] string pattern matching

2017-03-21 Thread David Winsemius
> On Mar 21, 2017, at 6:31 PM, Bert Gunter wrote: > > It is not clear to me what you mean, but: > >> grep ("x1 \\+.* \\+ x3",test, value = TRUE) > [1] "x1 + x2 + x3" > > ## This will miss "x1 + x3" though. So then this might be acceptable: grep ("x1\\ \\+.* x3", test, value = TRUE) > > se

Re: [R] string pattern matching

2017-03-21 Thread Bert Gunter
It is not clear to me what you mean, but: > grep ("x1 \\+.* \\+ x3",test, value = TRUE) [1] "x1 + x2 + x3" ## This will miss "x1 + x3" though. seems to do what you want, maybe. Perhaps you need to read up about regular expressions and/or clarify what you want to do. Cheers, Bert Bert Gunter "

Re: [R] string pattern matching

2017-03-21 Thread Jim Lemon
Hi Joe, This may help you: test <- c("x1", "x2", "x3", "x1 + x2 + x3") multigrep<-function(x1,x2) { xbits<-unlist(strsplit(x1," ")) nbits<-length(xbits) xans<-rep(FALSE,nbits) for(i in 1:nbits) if(length(grep(xbits[i],x2))) xans[i]<-TRUE return(all(xans)) } multigrep("x1 + x3","x1 + x2 + x3")

[R] string pattern matching

2017-03-21 Thread Joe Ceradini
Hi Folks, Is there a way to find "x1 + x2 + x3" given "x1 + x3" as the pattern? Or is that a ridiculous question, since I'm trying to find something based on a pattern that doesn't exist? test <- c("x1", "x2", "x3", "x1 + x2 + x3") test [1] "x1" "x2" "x3" "x1 + x2 +

Re: [R] String match

2016-06-04 Thread Bert Gunter
Please (re)-read the Help file for pmatch, which says: ... " (A partial match occurs if the whole of the element of x matches the beginning of the element of table.) " This is clearly not your situation. One approach (there may be others depending on what your detailed situation actually is) is t

Re: [R] String match

2016-06-04 Thread jim holtman
try this: > WhereToLook = c("ultracemco.bo.openam" , "ultracemco.bo.higham" + ,"ultracemco.bo.lowam" , "ultracemco.bo.closeam" , + "ultracemco.bo.volumeam" ,"ultracemco.bo.adjustedam") > > WhatToLook = c("volume", "close") > > # create pattern match > pat <- paste(WhatToLook, collaps

[R] String match

2016-06-04 Thread Christofer Bogaso
Hi again, I am facing trouble to match a vector strings. Let say I have below full string vector WhereToLook = c("ultracemco.bo.openam" , "ultracemco.bo.higham" ,"ultracemco.bo.lowam" , "ultracemco.bo.closeam" , "ultracemco.bo.volumeam" ,"ultracemco.bo.adjustedam") WhatToLook = c("vol

Re: [R] String Matching

2016-02-01 Thread PIKAL Petr
gt; -Original Message- > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Glenn > Schultz > Sent: Friday, January 29, 2016 6:02 PM > To: R Help R > Subject: [R] String Matching > > All, > > I have a file named as so 313929BL4FNMA2432.rds the user may

Re: [R] String Matching

2016-02-01 Thread Berend Hasselman
t six? > >> substr(id, nchar(id)-6, nchar(id))=="432.rds" > [1] TRUE >> > > Cheers > Petr > > >> -Original Message- >> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Glenn >> Schultz >> Sent: Friday, Ja

Re: [R] String Matching

2016-01-29 Thread Duncan Murdoch
On 29/01/2016 12:02 PM, Glenn Schultz wrote: All, I have a file named as so 313929BL4FNMA2432.rds the user may pass either the first 9 character or the last six characters. I need to match the remainder of the file name using either the first nine or last six. I have read the help files fo

[R] String Matching

2016-01-29 Thread Glenn Schultz
All, I have a file named as so 313929BL4FNMA2432.rds  the user may pass either the first 9 character or the last six characters.  I need to match the remainder of the file name using either the first nine or last six.  I have read the help files for Regular Expression as used in R and I think

Re: [R] string split problem

2015-10-23 Thread Jun Shen
Hi Marc/Bill Thanks for reply. That's exactly what I am looking for. Jun On Fri, Oct 23, 2015 at 3:53 PM, William Dunlap wrote: > > test <- c('aaa.bb.cc','aaa.dd', 'aaa', 'aaa.', '.eee', '') > > sub("([^.]*)(.*)", "\\1", test) > [1] "aaa" "aaa" "aaa" "aaa" """" > > sub("([^.]*)(.*)", "\\2",

Re: [R] string split problem

2015-10-23 Thread William Dunlap
> test <- c('aaa.bb.cc','aaa.dd', 'aaa', 'aaa.', '.eee', '') > sub("([^.]*)(.*)", "\\1", test) [1] "aaa" "aaa" "aaa" "aaa" """" > sub("([^.]*)(.*)", "\\2", test) [1] ".bb.cc" ".dd""" "." ".eee" "" Bill Dunlap TIBCO Software wdunlap tibco.com On Fri, Oct 23, 2015 at 12:17 PM,

Re: [R] string split problem

2015-10-23 Thread Marc Schwartz
> On Oct 23, 2015, at 2:17 PM, Jun Shen wrote: > > Dear list, > > Say I have a vector that has two different types of string > > test <- c('aaa.bb.cc','aaa.dd') > > I want to extract the first part of the string (aaa) as a name and save the > rest of the string as another name. > > I was thi

[R] string split problem

2015-10-23 Thread Jun Shen
Dear list, Say I have a vector that has two different types of string test <- c('aaa.bb.cc','aaa.dd') I want to extract the first part of the string (aaa) as a name and save the rest of the string as another name. I was thinking something like sub('(.*)\\.(.*)','\\1',test) but doesn't give me

Re: [R] String Matching

2015-08-13 Thread MacQueen, Don
I haven't tested this, but what about: df <- data.frame(mtch=c(matchString, string1, string2)) grep(searchString, df$mtch, ignore.case=FALSE) Depending on what your next step is, you might prefer grepl. Sometimes using fixed=TRUE in grep() helps. -Don -- Don MacQueen Lawrence Livermore Na

Re: [R] String Matching

2015-08-12 Thread Ista Zahn
Hi Kevin, It's not totally clear to me what the desired output is. grep(searchString, matchString, ignore.case=FALSE) told you that searchString is in the first element of matchString. Isn't that what you want to know? If not, perhaps you can be more specific about what the desired result is. B

[R] String Matching

2015-08-12 Thread Kevin Kowitski
Hey everyone,    I have been having an issue trying to find a specific string of text in a log of system messages.  I have tried to use pmatch, match, and some regular expressions but all to no avail.   I have a matrix / data.frame (either one, the file outputs a tens of thousands of rows wit

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"

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] ":"

[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 "h

Re: [R] String comparison, trailing blanks make a difference.

2014-07-19 Thread Hadley Wickham
If you have unicode strings, you may need to do even more because there are often multiple ways of representing the same glyph. I made a little demo at http://rpubs.com/hadley/unicode-normalisation, since any unicode characters are likely to get mangled by email. Hadley On Fri, Jul 18, 2014 at 11

Re: [R] String comparison, trailing blanks make a difference.

2014-07-19 Thread John McKown
On Fri, Jul 18, 2014 at 11:17 AM, John McKown wrote: > Well, this was a shock to me. And I don't really see any documentation > about it, but perhaps I just can't see it. > >>"abc" == "abc " > [1] FALSE > > I guess that I thought of strings in R like I do is some other > languages where the shorte

Re: [R] String comparison, trailing blanks make a difference.

2014-07-18 Thread Hervé Pagès
Hi John, On 07/18/2014 09:17 AM, John McKown wrote: Well, this was a shock to me. And I don't really see any documentation about it, but perhaps I just can't see it. "abc" == "abc" [1] FALSE I guess that I thought of strings in R like I do is some other languages where the shorter value is p

Re: [R] String comparison, trailing blanks make a difference.

2014-07-18 Thread William Dunlap
>>"abc" == "abc " > [1] FALSE R does no interpretation of strings when doing comparisons so you do have do your own canonicalization. That may involve removing trailing, leading, or all white space or punctuation, converting to lower or upper case, mapping nicknames to official names, trimming to

[R] String comparison, trailing blanks make a difference.

2014-07-18 Thread John McKown
Well, this was a shock to me. And I don't really see any documentation about it, but perhaps I just can't see it. >"abc" == "abc " [1] FALSE I guess that I thought of strings in R like I do is some other languages where the shorter value is padded with blanks to the length of the longer value, th

Re: [R] String substitution

2013-10-04 Thread irene
Wonderful! Thank you Arun! Irene   Irene Ruberto Da: arun kirshna [via R] Inviato: Giovedì 3 Ottobre 2013 22:51 Oggetto: Re: String substitution Hi, Try: dat$y<- as.character(dat$y) dat1<- dat dat2<- dat library(stringr)  dat$y[NET]<- substr(wor

Re: [R] String substitution

2013-10-03 Thread arun
Hi, Try: dat$y<- as.character(dat$y) dat1<- dat dat2<- dat library(stringr)  dat$y[NET]<- substr(word(dat$y[NET],2),1,1)  dat$y #[1] "n" "n" "house" "n" "tree" #or for(i in 1:length(NET)){dat1$y[NET[i]]<- "n"}  dat1$y #[1] "n" "n" "house" "n" "tree" #or dat2$y[NET]<- gsub

Re: [R] string processing(regular expressions)

2013-09-01 Thread arun
ot;,"C"),function(x) paste0(levels(nCourse),x)),stringsAsFactors=FALSE),c("B","P","C")) head(res) #    B   P   C #1 2AB 2AP 2AC #2 2BB 2BP 2BC #3 2CB 2CP 2CC #4 7AB 7AP 7AC #5 7BB 7BP 7BC #6 7CB 7CP 7CC A.K. - Original Message - From: Robert Lynch To: R hel

Re: [R] string processing(regular expressions)

2013-09-01 Thread Rui Barradas
Hello, Try the following. gsub("^0+", "", as.character(nCourse)) Hope this helps, Rui Barradas Em 01-09-2013 21:41, Robert Lynch escreveu: I have a variable that is course # nCourse <- as.factor(c("002A","002B","002C","007A","007B","007C","101","118A","118B","118C")) And I would like to ge

[R] string processing(regular expressions)

2013-09-01 Thread Robert Lynch
I have a variable that is course # nCourse <- as.factor(c("002A","002B","002C","007A","007B","007C","101","118A","118B","118C")) And I would like to get rid of the leading zeros, and have the following set ("2A","2B","2C","7A","7B","7C","101","118A","118B","118C") to paste() together with the depa

Re: [R] String based chemical name identification

2013-07-03 Thread Law, Jason
p-boun...@r-project.org] On Behalf Of Zsurzsa Laszlo Sent: Wednesday, July 03, 2013 7:28 AM To: r-help@r-project.org Subject: [R] String based chemical name identification The problem is the following: I have two big databases one look like this: 2-Methyl-4-trimethylsilyloxyoct-5-yne Benzoic a

[R] String based chemical name identification

2013-07-03 Thread Zsurzsa Laszlo
The problem is the following: I have two big databases one look like this: 2-Methyl-4-trimethylsilyloxyoct-5-yne Benzoic acid, methyl ester Benzoic acid, 2-methyl-, methyl ester Acetic acid, phenylmethyl ester 2,7-Dimethyl-4-trimethylsilyloxyoct-7-en-5-yne etc. The second one looks li

[R] string size limits in RCurl

2013-04-24 Thread Elmore, Ryan
; stream.json where `file.json` is a roughly 14MB json string. I can read the string into R using either con <- file(paste(.project.path, "data/stream.json", sep = ""), "r") string <- readLines(con) or directly to list as tmp <- fromJSON(file = p

Re: [R] string split at xth position

2013-03-13 Thread arun
b1" "0b" "b2" "40" let1<-unique(unlist(strsplit(gsub("\\d+","",x1),"")))  split(unlist(strsplit(gsub("(\\w\\d+)(\\w\\d+)","\\1 \\2",x1)," ")),let1) #$a #[1] "a1"   "a10"  "a2"  

[R] string split at xth position

2013-03-13 Thread Keith Weintraub
Here is another way require(stringr) aaa<-paste0("a", 1:20) bbb<-paste0("b", 101:120) ab<-paste0(aaa,bbb) ab ptrn<-"([ab][[:digit:]]*)" unlist(str_extract_all(ab, ptrn)) > Hi, > > I have a vector of strings like: > c("a1b1","a2b2","a1b2") which I want to spilt into two parts like: > c("a1"

Re: [R] string split at xth position

2013-03-13 Thread arun
o: r-help@r-project.org Cc: Sent: Wednesday, March 13, 2013 4:37 AM Subject: [R] string split at xth position Hi, I have a vector of strings like: c("a1b1","a2b2","a1b2") which I want to spilt into two parts like: c("a1","a2","a2") and c(

Re: [R] string split at xth position

2013-03-13 Thread Johannes Radinger
Thank you Jorge! thats working perfectly... /johannes On Wed, Mar 13, 2013 at 9:45 AM, Jorge I Velez wrote: > Dear Johannes, > > May not be the best way, but this looks like what you described: > >> x <- c("a1b1","a2b2","a1b2") >> x > [1] "a1b1" "a2b2" "a1b2" >> substr(x, 1, 2) > [1] "a1" "a2

Re: [R] string split at xth position

2013-03-13 Thread Jorge I Velez
Dear Johannes, May not be the best way, but this looks like what you described: > x <- c("a1b1","a2b2","a1b2") > x [1] "a1b1" "a2b2" "a1b2" > substr(x, 1, 2) [1] "a1" "a2" "a1" > substr(x, 3, 4) [1] "b1" "b2" "b2" HTH, Jorge.- On Wed, Mar 13, 2013 at 7:37 PM, Johannes Radinger <> wrote: > Hi,

[R] string split at xth position

2013-03-13 Thread Johannes Radinger
Hi, I have a vector of strings like: c("a1b1","a2b2","a1b2") which I want to spilt into two parts like: c("a1","a2","a2") and c("b1","b2,"b2"). So there is always a first part with a+number and a second part with b+number. Unfortunately there is no separator I could use to directly split the vecto

Re: [R] String Handling() for Split a word by a letter

2012-08-28 Thread Rantony
Here I have a variable called "Variable_1". Variable_1 <- "MyDataFrame" Here I want to create another variable, by assigning the value of "Variable_1" . So, it will come like, Assign(Variable_1,data.frame(read.csv("c:\\Mydata.csv"))) --->[this was the 1st requirement, now I got the s

Re: [R] String Handling() for Split a word by a letter

2012-08-28 Thread Jim Lemon
On 08/27/2012 07:29 PM, Rantony wrote: Hi, here im unable to run a string handle function called unpaste(). for eg:- a<- "12345_mydata" Actually my requirement what is i need to get , only 12345. Means that , i need the all letter as a word which is before of first " _ " - symbol of "a". i t

Re: [R] String Handling() for Split a word by a letter

2012-08-27 Thread Rui Barradas
Hello, If the op says he has tried strsplit, maybe a simple subsetting afterwards would solve it. a <- "12345_mydata" strsplit(a, "_")[[1]][1] Hope this helps, Rui Barradas Em 27-08-2012 15:22, jim holtman escreveu: Is this what you want: a<- "12345_mydata" sub("_.*", "", a) [1] "12345

Re: [R] String Handling() for Split a word by a letter

2012-08-27 Thread jim holtman
Is this what you want: > a<- "12345_mydata" > sub("_.*", "", a) [1] "12345" On Mon, Aug 27, 2012 at 5:29 AM, Rantony wrote: > Hi, > > here im unable to run a string handle function called unpaste(). > > for eg:- a<- "12345_mydata" > Actually my requirement what is i need to get , only 12345.

[R] String Handling() for Split a word by a letter

2012-08-27 Thread Rantony
Hi, here im unable to run a string handle function called unpaste(). for eg:- a<- "12345_mydata" Actually my requirement what is i need to get , only 12345. Means that , i need the all letter as a word which is before of first " _ " - symbol of "a". i tried to do with unpaste, it says functio

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 wrote: > ?grepl > > Note that this function uses regular expressions, in which certain cha

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: http://r.78

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 R. Michael Weylandt
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

[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 substitution for argument in function

2012-03-26 Thread R. Michael Weylandt
'elem' is an attribute (the name) of the 'data' variable (bad name for a variable), not something that is independently accessible. By very (exceptionally!) loose analogy, think of it as being something like a field/property of an object -- you can't get to it directly (and that's a good thing) but

Re: [R] string substitution for argument in function

2012-03-26 Thread Prof. Dr. Pedro Martinez Arbizu
HI, thanks Weidong, Henrique, this works for the example (may be a bad example, but it should be as simple as possible), This is however only a workaround to name the columns of a dataframe, but is not addressing the problem itself, that is, how can I substitute a string (used as argument in

Re: [R] string substitution for argument in function

2012-03-26 Thread Prof. Dr. Pedro Martinez Arbizu
Me again, what I really dont understand is the behaivour of R here. notice, elem is not written in "brackets", why it is interpreted as string and not as a variable? I would expect an error "elem not found" because it is not defined as variable, but in contrary it is accepted as column name, see

Re: [R] string substitution for argument in function

2012-03-25 Thread Henrique Dallazuanna
try this: `names<-`(rep(2, 3), a) On Sun, Mar 25, 2012 at 6:22 PM, Pedro Martinez wrote: > > hello, > I want to iterate through a list of names and use each element as an > argument in a function. For instance: > > > a = c('one','two','three') > > data= c() > > for(elem in a){data=cbind(elem =

Re: [R] string substitution for argument in function

2012-03-25 Thread Weidong Gu
Hi, This may help a = c('one','two','three') data.frame(eval(substitute(rbind(var,2),list(var=a ?substitute ?eval Weidong Gu On Sun, Mar 25, 2012 at 5:22 PM, Pedro Martinez wrote: > hello, > I want to iterate through a list of names and use each element as an > argument in a function. F

[R] string substitution for argument in function

2012-03-25 Thread Pedro Martinez
hello, I want to iterate through a list of names and use each element as an argument in a function. For instance: > a = c('one','two','three') > data= c() > for(elem in a){data=cbind(elem = 2,data)} > data elem elem elem [1,]222 instead I want 'elem' to be substituted by the stri

Re: [R] String position character replacement

2012-02-08 Thread Yang, Joy (NIH/NHGRI) [F]
Oh cool! I didn't realize you could assign a different value to a substring like that. Thanks! Joy From: Petr Savicky [savi...@cs.cas.cz] Sent: Wednesday, February 08, 2012 3:26 PM To: r-help@r-project.org Subject: Re: [R] String position char

Re: [R] String position character replacement

2012-02-08 Thread Henrique Dallazuanna
Try this: sapply(mapply(replace, x = strsplit(avec, NULL), list = alist, MoreArgs = list(values = "-")), paste, collapse = "") On Wed, Feb 8, 2012 at 3:33 PM, Yang, Joy (NIH/NHGRI) [F] wrote: > Hi, > > Is there a way to efficiently replace specified indices in a string with > another character?

Re: [R] String position character replacement

2012-02-08 Thread Petr Savicky
On Wed, Feb 08, 2012 at 01:30:55PM -0500, Sarah Goslee wrote: > And here's an alternative solution: > > subchar <- function(string, pos, char="-") { > for(i in pos) { > string <- gsub(paste("^(.{", i-1, "}).", sep=""), "\\1-", string) > } > string > } Hi. Try the followin

Re: [R] String position character replacement

2012-02-08 Thread Yang, Joy (NIH/NHGRI) [F]
M To: Yang, Joy (NIH/NHGRI) [F] Cc: r-help@R-project.org Subject: Re: [R] String position character replacement And here's an alternative solution: subchar <- function(string, pos, char="-") { for(i in pos) { string <- gsub(paste("^(.{&q

Re: [R] String position character replacement

2012-02-08 Thread Gabor Grothendieck
On Wed, Feb 8, 2012 at 12:33 PM, Yang, Joy (NIH/NHGRI) [F] wrote: > Hi, > > Is there a way to efficiently replace specified indices in a string with > another character? For example, if I had a vector of strings such as > > [1] "hellohowareyoudoing" > [2] "imgoodhowareyou" > [3] "goodandyou" > [4

Re: [R] String position character replacement

2012-02-08 Thread Sarah Goslee
And here's an alternative solution: subchar <- function(string, pos, char="-") { for(i in pos) { string <- gsub(paste("^(.{", i-1, "}).", sep=""), "\\1-", string) } string } > subchar("hellohowareyoudoing", 3) [1] "he-lohowareyoudoing" > subchar("hellohowareyoudo

Re: [R] String position character replacement

2012-02-08 Thread Jorge I Velez
Hi Joy, Perhaps not the easiest way, but the following seems to work: x <- c("hellohowareyoudoing", "imgoodhowareyou", "goodandyou", "yesimgoodijusttoldyou", "ohyesthatsright") pos <- list(c(3, 9), c(3,4), c(4,7), 5:9, c(2, 5, 7, 12)) sapply(1:length(pos), function(i){ xx <- strsplit(x, "")[

[R] String position character replacement

2012-02-08 Thread Yang, Joy (NIH/NHGRI) [F]
Hi, Is there a way to efficiently replace specified indices in a string with another character? For example, if I had a vector of strings such as [1] "hellohowareyoudoing" [2] "imgoodhowareyou" [3] "goodandyou" [4] "yesimgoodijusttoldyou" [5] "ohyesthatsright" and had a list of positions that I

Re: [R] string to list()

2011-11-14 Thread Bert Gunter
Do it in 2 steps: z <- as.list( coef(am)[1:am$arma[2] + am$arma[1]]) names(z) <- paste("ma",seq_along(z), sep="") -- Bert On Mon, Nov 14, 2011 at 10:40 AM, Kevin Burton wrote: > I can get an array of strings for the data that I want using 'paste()' as > follows: > > > > paste('ma', 1:am$arma[2]

[R] string to list()

2011-11-14 Thread Kevin Burton
I can get an array of strings for the data that I want using 'paste()' as follows: paste('ma', 1:am$arma[2], '=', coef(am)[1:am$arma[2] + am$arma[1]], sep='') This results in a vector of strings like: [1] "ma1=1.17760133668255" "ma2=0.649795570407939" "ma3=0.329456750858276" What I

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 man

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 (

[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 what

Re: [R] string manipulation

2011-08-26 Thread Gabor Grothendieck
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

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: Basics: ##.#. ##.#. Live Go... Live: OO

Re: [R] string manipulation

2011-08-26 Thread Gabor Grothendieck
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

Re: [R] string manipulation

2011-08-26 Thread Janko Thyson
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

Re: [R] string manipulation

2011-08-25 Thread Lorenzo Cattarino
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

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,

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] nynumbers<-

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 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

[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 thi

Re: [R] String manipulation

2011-06-26 Thread Gabor Grothendieck
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

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

Re: [R] String manipulation

2011-06-26 Thread Gabor Grothendieck
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

[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 elemen

Re: [R] R string functions

2011-06-15 Thread karena
Thank all you guys for the great help~. I appreciate -- View this message in context: http://r.789695.n4.nabble.com/R-string-functions-tp3600484p3600975.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list

Re: [R] R string functions

2011-06-15 Thread Steve Lianoglou
Hi, On Wed, Jun 15, 2011 at 4:37 PM, karena wrote: > Hi, > > I have a string "GGCCCAATCGCAATTCCAATT" > > What I want to do is to count the percentage of each letter in the string, > what string functions can I use to count the number of each letter appearing > in the string? > > For example,

Re: [R] R string functions

2011-06-15 Thread Peter Alspach
a.m. > To: r-help@r-project.org > Subject: [R] R string functions > > Hi, > > I have a string "GGCCCAATCGCAATTCCAATT" > > What I want to do is to count the percentage of each letter in the > string, > what string functions can I use to count the number of

[R] R string functions

2011-06-15 Thread karena
;T" appeared 5 times, how can I use a string function to get the these number? thanks, karena -- View this message in context: http://r.789695.n4.nabble.com/R-string-functions-tp3600484p3600484.html Sent from the R help mailing list archive at Nabble.com. _

  1   2   3   >