[R] applying strsplit to a whole column

Joshua Wiley jwiley.psych at gmail.com
Wed Aug 4 20:06:32 CEST 2010


Hi,

You already have great solutions.  I just wanted to point out that

A) strsplit() works on the entire column automatically so you would
not need a loop
B) with the argument stringsAsFactors = FALSE, your character data
will not be converted to factor, so you would not need to convert it
back.

x <- data.frame(names = c("X..aba","X..abb","X..abc","X..abd"),
                stringsAsFactors = FALSE)
str(x)

Cheers,

Josh

On Wed, Aug 4, 2010 at 10:42 AM, Dimitri Liakhovitski
<dimitri.liakhovitski at gmail.com> wrote:
> I am sorry, I'd like to split my column ("names") such that all the
> beginning of a string ("X..") is gone and only the rest of the text is
> left.
>
> x<-data.frame(names=c("X..aba","X..abb","X..abc","X..abd"))
> x$names<-as.character(x$names)
> (x)
> str(x)
>
> Can't figure out how to apply strsplit in this situation - without
> using a loop. I hope it's possible to do it without a loop - is it?
>
> Thanks a lot!
>
>
> --
> Dimitri Liakhovitski
> Ninah Consulting
> www.ninah.com
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/



More information about the R-help mailing list