Re: [R] split a row into multiple columns

From: Kevin Burnham <kburnham_at_gmail.com>
Date: Fri, 04 Jun 2010 13:42:18 -0500

Thanks, that worked great, but I am having trouble generalizing it to my entire data set for some reason.

I have 318 rows like this:

"Main Group\t1000\tMP Test\tMP Test, 1\tAudio (1, f1-qaddara.aiff)\tl (target is right word)\tl\tPressed\tl (target is right word)\tC\t3111\t\t\t\t\t"

and the command:
mydata <- matrix(strsplit(x, '\t')[[1]], nrow=1)

gives me a matrix with only the 1st row of the data. I have tried playing around with it, but so far the best I can do is get 318 copies of row 1.

How can I get a matrix with all 318 rows and 15 columns split by the '\t'?

Thanks again.

kevin

On Thu, Jun 3, 2010 at 2:39 PM, jim holtman <jholtman_at_gmail.com> wrote:

> If you want a matrix, then just create one from the data you have:
>
> mydata <- matrix(strsplit(x, '\t')[[1]], nrow=1)
>
> On Thu, Jun 3, 2010 at 1:30 PM, Kevin Burnham <kburnham_at_gmail.com> wrote:
> > Would somebody please help me break this row:
> >
> > "Main Group\t1000\tMP Test\tMP Test, 1\tAudio (1, f1-qaddara.aiff)\tl
> > (target is right word)\tl\tPressed\tl (target is right
> > word)\tC\t3111\t\t\t\t\t"
> >
> > into multiple columns along the \t separator?
> >
> > When I try the strsplit (x,"\t") command I get:
> >
> > [[1]]
> > [1] "Main Group" "1000" "MP
> > Test" "MP Test, 1" "Audio (1,
> > f1-qaddara.aiff)"
> > [6] "l (target is right word)" "l"
> > "Pressed" "l (target is right word)"
> > "C"
> > [11] "3111" ""
> > "" "" ""
> >
> > Which which is closer to what I need, but still not in columns.
> >
> > Thanks,
> > Kevin
> >
> > [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > 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.
> >
>
>
>
> --
> Jim Holtman
> Cincinnati, OH
> +1 513 646 9390
>
> What is the problem that you are trying to solve?
>

        [[alternative HTML version deleted]]



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. Received on Fri 04 Jun 2010 - 18:45:02 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 04 Jun 2010 - 19:40:27 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive