[R] problem with read.table

jim holtman jholtman at gmail.com
Sun Jul 20 12:42:55 CEST 2008


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?



More information about the R-help mailing list