Re: [R] problem with read.table

From: jim holtman <jholtman_at_gmail.com>
Date: Sun, 20 Jul 2008 06:42:55 -0400

If you really want to do it, here is a way, but don't expect to be able to reference the columns by name; this is just so it 'prints pretty':

> x <- textConnection("AM2 AM2 AM2 FAL

+ 2               3             4         5
+ 1               -1           -3        -2")

> # read the header row
> header <- read.table(x, as.is=TRUE, nrows=1)
> # read in the rest of the data
> myData <- read.table(x, header=FALSE)
> # put header on the table
> colnames(myData) <- header
> myData

  AM2 AM2 AM2 FAL
1 2 3 4 5
2 1 -1 -3 -2
> myData$AM2 # only gives the first column
[1] 2 1

On Sun, Jul 20, 2008 at 3:45 AM, carol white <wht_crl_at_yahoo.com> wrote:
> Hi,
> Although I set check.names to FALSE in read.table, the duplicate names get modified. What should be done in this case?
>
> the text file to be read by read.table
>
> AM2 AM2 AM2 FAL
> 2 3 4 5
> 1 -1 -3 -2
>
> t = read.table ("my_file", check.names = FALSE, header = T)
>
>> t
> AM2 AM2.1 AM2.2 FAL
>
> 2 3 4 5
>
> 1 -1 -3 -2
>
> instead of
>
> AM2 AM2 AM2 FAL
>
>
> 2 3 4 5
>
>
> 1 -1 -3 -2
>
>
> Best,
> carol
>
>
>
>
> [[alternative HTML version deleted]]
>
>
> ______________________________________________
> 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.
>
>

-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

______________________________________________
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.
Received on Sun 20 Jul 2008 - 10:47:15 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 20 Jul 2008 - 11:31:57 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive