Re: [R] Q about strsplit and regexp

2004-10-20 Thread Gabor Grothendieck
John Fox mcmaster.ca> writes: : This is something that I sometimes want to do, so I have a little utility : that trims blanks and tabs from the beginnings and ends of strings: : : trim.ws <- function(text) gsub("^[\ \t]", "", gsub("[\ \t]*$", "", text)) : This can be reduced to a single gsub l

Re: [R] Q about strsplit and regexp

2004-10-20 Thread Gabor Grothendieck
Liaw, Andy merck.com> writes: : > I do not want that empty character in the beginning, but : > couldn't figure out : > how to strip the starting white spaces, other than something : > ugly like: : > : > > strsplit(sub("^ +", "", " a bc "), " +") : > [[1]] : > [1] "a" "b" "c" : : Looks l

Re: [R] Q about strsplit and regexp

2004-10-20 Thread Arne Henningsen
Dear Andy, I also don't know a regular expression that does what you want. However, if you have to do this several times, you can avoid the 'ugly' command by: > mystrsplit <- function( str ) strsplit(sub("^ +", "", str), " +") > mystrsplit( " a bc ") [[1]] [1] "a" "b" "c" > mystrsplit( " d

RE: [R] Q about strsplit and regexp

2004-10-20 Thread Liaw, Andy
Thanks to Barry Rawlingson, Peter Dalgaard, Jean-Pierre Muller, Dimitris Rizopoulos, John Fox, and Stephen Upton for comments and suggestions. Looks like there's no easier way than to strip the spaces before splitting the fields. Several people suggested deleting the empty strings afterwards. In

RE: [R] Q about strsplit and regexp

2004-10-20 Thread Stephen Upton
t: Wednesday, October 20, 2004 8:16 AM > To: R-Help > Subject: [R] Q about strsplit and regexp > > Dear R-help, > > This one is probably a piece of cake for regexp masters. I'd like to > split > a character vector (for simplicity, say of length one for now) that >

RE: [R] Q about strsplit and regexp

2004-10-20 Thread John Fox
Of Liaw, Andy > Sent: Wednesday, October 20, 2004 7:16 AM > To: R-Help > Subject: [R] Q about strsplit and regexp > > Dear R-help, > > This one is probably a piece of cake for regexp masters. I'd > like to split a character vector (for simplicity, say of > l

Re: [R] Q about strsplit and regexp

2004-10-20 Thread Dimitris Rizopoulos
;[EMAIL PROTECTED]> Sent: Wednesday, October 20, 2004 2:15 PM Subject: [R] Q about strsplit and regexp Dear R-help, This one is probably a piece of cake for regexp masters. I'd like to split a character vector (for simplicity, say of length one for now) that contains fields that are delim

Re: [R] Q about strsplit and regexp

2004-10-20 Thread Jean-Pierre Muller
Hello, in the function ttda.segmentation of ttda i use: #compute occurences occurences <- unlist(strsplit(textlines[1:length(textlines)], grep.sep, TRUE)) #delete empty lines occurences <- occurences[nchar(occurences) > 0] HT

[R] Q about strsplit and regexp

2004-10-20 Thread Liaw, Andy
Dear R-help, This one is probably a piece of cake for regexp masters. I'd like to split a character vector (for simplicity, say of length one for now) that contains fields that are delimited by arbitrary number of white spaces (e.g., " a b c "). How do I get the character vector that contain th