Re: [Rd] Scan data from a .txt file

From: Duncan Murdoch <murdoch_at_stats.uwo.ca>
Date: Thu 17 Nov 2005 - 16:13:36 GMT

On 11/17/2005 10:35 AM, Vasundhara Akkineni wrote:
> Hi all,
> Am trying to read data from a .txt file in such a way that i can access the
> column names too. For example, the data in the table.txt file is as below:
> Name Weight Height Gender
> Anne 150 65 F
> Rob 160 68 M
> George 180 65 M
> Greg 205 69 M
> i used the following commands:
> data<-scan("table.txt",list("",0,0,0),sep="")
> a<-data[[1]]
> b<-data[[2]]
> c<-data[[3]]
> d<-data[[4]]
> But this doesn't work because of type mismatch. I want to pull the col
> names also into the respective lists. For example i want 'b' to have
> (weight,150,160,180,205) so that i can access the col name and also the
> induvidual weights. I tried using the read.table method too, but couldn't
> get this working. Can someone suggest a way to do this.

You probably want to use read.table("table.txt", head=TRUE). Chances are it will automatically recognize the column types; if not, there's the colClasses argument.

Duncan Murdoch



R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Fri Nov 18 03:20:38 2005

This archive was generated by hypermail 2.1.8 : Thu 17 Nov 2005 - 21:21:18 GMT