I want to retrieve the column names(Weight, height, Gender) so that i can
use them as labels in plots further down.
 According to your suggestion:
  dat[[1]]
[1] 150 160 180 205

But i want to get the col name(weight) too. A user will upload any data file
and i shud be able to access the col names so that i can use them as axis
labels for plots i will be doing on the data. Hope i have clarified my
problem.
 Thanks,
Vasu.
 On 11/17/05, Liaw, Andy <andy_liaw@merck.com> wrote:
>
> [Re-directing to R-help, as this is more appropriate there.]
>
> I tried copying the snippet of data into the windows clipboard and tried
> it:
>
> > dat <- read.table("clipboard", header=T)
> > dat
> Name Weight Height Gender
> 1 Anne 150 65 F
> 2 Rob 160 68 M
> 3 George 180 65 M
> 4 Greg 205 69 M
> > str(dat)
> `data.frame': 4 obs. of 4 variables:
> $ Name : Factor w/ 4 levels "Anne","George",..: 1 4 2 3
> $ Weight: int 150 160 180 205
> $ Height: int 65 68 65 69
> $ Gender: Factor w/ 2 levels "F","M": 1 2 2 2
> > dat <- read.table("clipboard", header=T, row=1)
> > str(dat)
> `data.frame': 4 obs. of 3 variables:
> $ Weight: int 150 160 180 205
> $ Height: int 65 68 65 69
> $ Gender: Factor w/ 2 levels "F","M": 1 2 2 2
> > dat
> Weight Height Gender
> Anne 150 65 F
> Rob 160 68 M
> George 180 65 M
> Greg 205 69 M
>
> Don't see how it "doesn't work". Please give more detail on what "doesn't
> work" means.
>
> Andy
>
> > From: Vasundhara Akkineni
> >
> > 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.
> > Thanks,
> > Vasu.
> >
> > [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-devel@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
> >
> >
>
>
>
> ------------------------------------------------------------------------------
> Notice: This e-mail message, together with any attachments...{{dropped}}


