Re: [R] spliting strings ...

2007-12-13 Thread Moshe Olshansky
Hi Monica, Try sapply(as.list(str),function(x) unlist(strsplit(x," "))[1]) --- Monica Pisica <[EMAIL PROTECTED]> wrote: > > Hi everyone, > > I have a vector of strings, each string made up by > different number of words. I want to get a new > vector which has only the first word of each str

Re: [R] spliting strings ... THANKS!

2007-12-13 Thread Monica Pisica
> Subject: Re: [R] spliting strings ...> > Monica Pisica wrote:> > Hi everyone,> > > > I have a vector of strings, each string made up by different number of words. I want to get a new vector which has only the first word of each string in the first vector. I came up with this

Re: [R] spliting strings ...

2007-12-13 Thread Prof Brian Ripley
On Thu, 13 Dec 2007, Monica Pisica wrote: > > Hi everyone, > > I have a vector of strings, each string made up by different number of > words. You need to define 'word' and 'first'. Your solution says the first word of " aa" is "", which is not what most people would think. > I want to get a

Re: [R] spliting strings ...

2007-12-13 Thread seanpor
Good afternoon Monica, Relying on regular expressions, substituting nothing "" for everything starting with a space until the end of the "line" (i.e. with a dollar sign) str1 <- sub(" .*$", "", str) Regards, Sean Monica Pisica wrote: > > > Hi everyone, > > I have a vector of strings, eac

Re: [R] spliting strings ...

2007-12-13 Thread Peter Dalgaard
Monica Pisica wrote: > Hi everyone, > > I have a vector of strings, each string made up by different number of words. > I want to get a new vector which has only the first word of each string in > the first vector. I came up with this: > > str <- c('aaa bbb', 'cc', 'd eee aa', 'mmm o n') > st

Re: [R] spliting strings ...

2007-12-13 Thread Dimitris Rizopoulos
; To: <[EMAIL PROTECTED]> Sent: Thursday, December 13, 2007 2:41 PM Subject: [R] spliting strings ... > > Hi everyone, > > I have a vector of strings, each string made up by different number > of words. I want to get a new vector which has only the first word > of e

Re: [R] spliting strings ...

2007-12-13 Thread Romain Francois
Hi, if you only want the first word, then this should do the trick : R> sub( " +.*", "", str ) [1] "aaa" "cc" "d" "mmm" Cheers, Romain Monica Pisica wrote: > Hi everyone, > > I have a vector of strings, each string made up by different number of words. > I want to get a new vector which

[R] spliting strings ...

2007-12-13 Thread Monica Pisica
Hi everyone, I have a vector of strings, each string made up by different number of words. I want to get a new vector which has only the first word of each string in the first vector. I came up with this: str <- c('aaa bbb', 'cc', 'd eee aa', 'mmm o n') str1 <- rep(1, length(str)) for (i in