On 4/14/2011 2:04 PM, Cliff Clive wrote:
I have a vector of character strings that I would like to split in two, and
place in columns of a dataframe.
So for example, I start with this:
beatles<- c("John Lennon", "Paul McCartney", "George Harrison", "Ringo
Starr")
and I want to end up with a da
On 15/04/11 09:04, Cliff Clive wrote:
I have a vector of character strings that I would like to split in two, and
place in columns of a dataframe.
So for example, I start with this:
beatles<- c("John Lennon", "Paul McCartney", "George Harrison", "Ringo
Starr")
and I want to end up with a data
You could use ?unlist:
structure(data.frame(
matrix(unlist(strsplit(beatles," ")),length(beatles),2,T)),
names=c("FirstName","LastName"))
Note that this compact code does not guard you against typos, that is
names with >2 or <2 elements.
Hope that helps,
Denes
> I have a vector of ch
3 matches
Mail list logo