[R] Why strsplit can be used with matrix but not data.frame?

Henrik Bengtsson hb at stat.berkeley.edu
Thu Sep 17 03:30:26 CEST 2009


have a look at help(str) - the str() function will be your friend for life!

...and 99.9% of the error message in R are indeed correct, on the spot
and informative.

So, try str(x$y).

My $.02


On Wed, Sep 16, 2009 at 6:22 PM, Peng Yu <pengyu.ut at gmail.com> wrote:
> Hi,
> As show in the code below, strsplit can be applied to a matrix but not
> a data.frame. I don't understand why R is designed in this way. Can
> somebody help me understand it? How to split all the strings in x$y?
> x=data.frame(x=1:10,y=rep("abc",10))
> strsplit(x$y,'b') #Error in strsplit(x$y, "b") : non-character argument
> y=cbind(1:10,rep("abc",10))
> strsplit(y[,2],'b')
> Regards,
> Peng
> ______________________________________________
> 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.

More information about the R-help mailing list