From murdoch at stats.uwo.ca  Thu Nov 17 17:13:36 2005
From: murdoch at stats.uwo.ca (Duncan Murdoch)
Date: Thu, 17 Nov 2005 11:13:36 -0500
Subject: [Rd] Scan data from a .txt file
In-Reply-To: <3b67376c0511170735m1c9120cfjee0b4d4fe59d2740@mail.gmail.com>
References: <3b67376c0511170735m1c9120cfjee0b4d4fe59d2740@mail.gmail.com>
Message-ID: <437CAC30.80709@stats.uwo.ca>

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



[Rd] Scan data from a .txt file
Duncan Murdoch