Skip to content
Prev 256919 / 398506 Next

Creating a dataframe from a vector of character strings

On 15/04/11 09:04, Cliff Clive wrote:
Whenever you think of using a for loop, stop and think about using
some flavour of apply() instead:

melvin <- strsplit(beatles," ")
clyde <- data.frame(firstName=sapply(melvin,function(x){x[1]}),
                                     
lastName=sapply(melvin,function(x){x[2]}))

     cheers,

             Rolf Turner