[R] Odp: Re ad in a file - produce independent vectors
Petr PIKAL
petr.pikal at precheza.cz
Fri Jul 4 17:07:10 CEST 2008
Hi
r-help-bounces at r-project.org napsal dne 04.07.2008 16:38:08:
>
> Is there a way of reading in a file in a way that each line becomes a
vector:
> for example:
>
> meals.txt
>
> breakfast bacon eggs sausage
> lunch sandwich apple marsbar crisps
> dinner chicken rice custard pie
>
> I want to read in this file and end up with 3 different vectors, one
called
> breakfast which contains "bacon", "eggs", sausage" One called lunch with
> "sandwich", "apple"... etc
You can read it through
read.table("meals.txt", sep="", header=F, fill=T, as.is=T)
see ?read.table for info about parameters.
You will get data frame and then you can manipulate it easily. It depends
what do you want to do next with your food.
Regards
Petr
>
> So is there a way to do this with a file like this?
>
> Or would I need to transpose the file using something like Perl? And
since
> the vectors are not all of equal length, would I have to also increase
the
> size of the shorter lines by adding NAs? I'm working with a file much
bigger
> than this and this could be a bit of a bother...
>
> Kind Regards,
>
> Jim
> --
> View this message in context:
http://www.nabble.com/Read-in-a-file---produce-
> independent-vectors-tp18280318p18280318.html
> Sent from the R help mailing list archive at Nabble.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.
More information about the R-help
mailing list