Re: [R] hyphen replaced by period in header when using read.table

2013-01-23 Thread Sarah Goslee
Please read ?read.table again, and pay special attention to the
check.names argument.

A - is not allowed in a column name because it would lead to problems like:

mydata$a-b vs mydata$a - b
where
mydata$a.b has no such confusion.

If you must have - instead of ., you can use check.names=FALSE and
make sure that you always access the columns using:
mydata[, "a-b"] or mydata["a-b"] instead of with the $ shortcut.

> mydata <- data.frame(col1 = 1:3, "a-b" = 4:6, check.names=FALSE)
> mydata
  col1 a-b
11   4
22   5
33   6

Sarah


On Wed, Jan 23, 2013 at 1:50 PM,   wrote:
> To Whom It May Concern:
>
> I have noticed that all of the hyphens ("-") are changed to periods (".") 
> when I try to read.table() and the headers contain "-"
>
> I am using R 2.13 on a RedHat system.
>
> Here is the situation:
>
> I have the following a tab-delimited text file saved as test.txt
>
> File1-a.txt
>
> File1-b.txt
>
> File2-a.txt
>
> File2-b.txt
>
> 1
>
> 1
>
> 2
>
> 1
>
> 1
>
> 2
>
> 3
>
> 2
>
> 1
>
> 1
>
> 2
>
> 3
>
> 1
>
> 2
>
> 3
>
> 4
>
>
>
>
> When I use:
>>example <- read.table("test.txt", header = TRUE, sep = "\t")
>
>>example
> File1.a.txt
>
> File1.b.txt
>
> File2.a.txt
>
> File2.b.txt
>
> 1
>
> 1
>
> 2
>
> 1
>
> 1
>
> 2
>
> 3
>
> 2
>
> 1
>
> 1
>
> 2
>
> 3
>
> 1
>
> 2
>
> 3
>
> 4
>
>
> Notice that all of the "-" are changed to "."
>
> I read the help(read.table) along with a google search, but I can't find why 
> this is happening.
>
> Is there a way to prevent this from happening?
>
> Thanks in advance,
> Mike
>

--
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@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.


[R] hyphen replaced by period in header when using read.table

2013-01-23 Thread Michael.Dufault
To Whom It May Concern:

I have noticed that all of the hyphens ("-") are changed to periods (".") when 
I try to read.table() and the headers contain "-"

I am using R 2.13 on a RedHat system.

Here is the situation:

I have the following a tab-delimited text file saved as test.txt

File1-a.txt

File1-b.txt

File2-a.txt

File2-b.txt

1

1

2

1

1

2

3

2

1

1

2

3

1

2

3

4




When I use:
>example <- read.table("test.txt", header = TRUE, sep = "\t")

>example
File1.a.txt

File1.b.txt

File2.a.txt

File2.b.txt

1

1

2

1

1

2

3

2

1

1

2

3

1

2

3

4


Notice that all of the "-" are changed to "."

I read the help(read.table) along with a google search, but I can't find why 
this is happening.

Is there a way to prevent this from happening?

Thanks in advance,
Mike


[[alternative HTML version deleted]]

__
R-help@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.