[R] [Rd] Scan data from a .txt file
Liaw, Andy
andy_liaw at merck.com
Thu Nov 17 16:41:43 CET 2005
[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 at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>
More information about the R-help
mailing list