Re: [R] Working with string

2013-08-11 Thread arun
t;ppbzJG" "ppbzJG" A.K. From: Christofer Bogaso To: arun Cc: R help ; Bert Gunter Sent: Sunday, August 11, 2013 2:19 PM Subject: Re: [R] Working with string Hello Arun, Thank you for your prompt reply. However if I use your new code, I am no

Re: [R] Working with string

2013-08-11 Thread Bert Gunter
Christopher: Yes, I warned you about both cases: In your second example there is no match since there is no nonupper case version of the all upper case entries. As you did not specify what should be done in that case, I leave it to you to figure out the necessary modifications of my code. Possibl

Re: [R] Working with string

2013-08-11 Thread Christofer Bogaso
t; chnew[duplicated(toupper(CH1))]<- > CH1[duplicated(toupper(CH1),fromLast=TRUE)] > sort(chnew) > #[1] "MRTZIt" "MRTZIt" "ppbzJG" "ppbzJG" > A.K. > > > > > From: Christofer Bogaso > To: Bert G

Re: [R] Working with string

2013-08-11 Thread arun
MRTZIt" "ppbzJG" "ppbzJG" A.K. From: Christofer Bogaso To: Bert Gunter Cc: arun ; R help Sent: Sunday, August 11, 2013 1:54 PM Subject: Re: [R] Working with string Thanks Bert and Arun for your help. As Bert already pointed out, Arun's co

Re: [R] Working with string

2013-08-11 Thread Christofer Bogaso
Thanks Bert and Arun for your help. As Bert already pointed out, Arun's code is working well, however except this: > CH <- c("MRTZIt", "MRTZIT", "PPBZJG", "ppbzJG") > chnew<-CH > chnew[duplicated(toupper(CH))]<-CH[duplicated(toupper(CH),fromLast=TRUE)] > CH [1] "MRTZIt" "MRTZIT" "PPBZJG" "ppbzJG"

Re: [R] Working with string

2013-08-11 Thread Bert Gunter
Well, maybe: it assumes that the uppercase string version always occurs after the nonuppercase version. That's why I rejected it. However, it points out something important: details matter. The more one knows about the nature of the problem, the better the solution one can tailor -- a remark for w

Re: [R] Working with string

2013-08-11 Thread arun
Hi, May be this helps: chnew<-CH  chnew[duplicated(toupper(CH))]<-CH[duplicated(toupper(CH),fromLast=TRUE)]  chnew #[1] "aBd"    "sTb"    "aBd"    "dFDasd" "asd"    "dFDasd" A.K. - Original Message - From: Christofer Bogaso To: r-help Cc: Sent: Sunday, August 11, 2013 8:39 AM Subjec

Re: [R] Working with string

2013-08-11 Thread Bert Gunter
Oh, sorry. One type. Here's the correct version On Sun, Aug 11, 2013 at 7:54 AM, Bert Gunter wrote: > Christofer: > > You may have to fortify the following a bit to allow for the > possibility that some of your caps strings don't match. But other than > that, I think this will do: > >> CH <- c("a

Re: [R] Working with string

2013-08-11 Thread Bert Gunter
Christofer: You may have to fortify the following a bit to allow for the possibility that some of your caps strings don't match. But other than that, I think this will do: > CH <- c("aBd", "sTb", "ABD", "dFDasd", "asd", "DFDASD") > caps <- CH %in% z > noncaps <- CH[!caps] > chnew <- CH > chnew[ca

Re: [R] Working with string

2013-03-14 Thread arun
format(Vec,justify="right") #[1] " sada" "asdsa" "   sa" A.K. - Original Message - From: Marc Schwartz To: Christofer Bogaso Cc: r-help Sent: Thursday, March 14, 2013 11:02 AM Subject: Re: [R] Working with string On Mar 14, 2013, at 9:42 AM, Christofe

Re: [R] Working with string

2013-03-14 Thread Bert Gunter
Duhhh... You already knew about nchar!! So (untested): nc <- nchar(vec) mx <- max(nc) blanks <- rep(" ",mx-nchar+1) ## +1 needed for rep paddedvec <-substring(paste(vec,blanks,sep=""),1,mx) You can also do this at one go with str_pad in the stringr package, found by searching on "pad strings.'

Re: [R] Working with string

2013-03-14 Thread Marc Schwartz
On Mar 14, 2013, at 9:42 AM, Christofer Bogaso wrote: > Hello again, > > Let say I have following string: > > Vec <- c("sada", "asdsa", "sa") > > Now I want to make each element of this vector with equal length. > Basically I want following vector: > > c("sada ", "asdsa", "sa ") > > There

Re: [R] Working with string

2013-03-14 Thread arun
library(stringr)  str_pad(Vec,5,"right") #[1] "sada " "asdsa" "sa   " #or str_pad(Vec,max(nchar(Vec)),"right") #[1] "sada " "asdsa" "sa   " str_count(str_pad(Vec,5,"right"),"") #[1] 5 5 5 A.K. - Original Message - From: Christofer Bogaso To: r-help Cc: Sent: Thursday, March 14, 20

Re: [R] Working with string

2013-03-14 Thread Bert Gunter
?nchar will tell you how many characters are in each string (mod multibyte locales) and you can use this to extend any that are shorter than the max with blanks or whatever. -- Bert On Thu, Mar 14, 2013 at 7:42 AM, Christofer Bogaso < bogaso.christo...@gmail.com> wrote: > Hello again, > > Let

Re: [R] Working with string

2011-07-07 Thread Marc Schwartz
nks, > > -Original Message- > From: Marc Schwartz [mailto:marc_schwa...@me.com] > Sent: 07 July 2011 21:54 > To: Bogaso Christofer > Cc: r-help@r-project.org > Subject: Re: [R] Working with string > > On Jul 7, 2011, at 11:21 AM, Bogaso Christofer wrote: >

Re: [R] Working with string

2011-07-07 Thread Bogaso Christofer
t: 07 July 2011 21:54 To: Bogaso Christofer Cc: r-help@r-project.org Subject: Re: [R] Working with string On Jul 7, 2011, at 11:21 AM, Bogaso Christofer wrote: > Hi there, I have to extract some relevant portion from a defined > string, which is a mix of numeric and character. However this

Re: [R] Working with string

2011-07-07 Thread Marc Schwartz
On Jul 7, 2011, at 11:21 AM, Bogaso Christofer wrote: > Hi there, I have to extract some relevant portion from a defined string, > which is a mix of numeric and character. However this has following > sequence: > > > > Some String - Some numerical - "c/C" (or "p/P") - then again some set of > n