"X" in front of my column names - I want it to stop!!

#1
I have a .csv file that I am trying to load into R. The problem is, it is putting an "X" in front of all of my column names (yes, they all start with numbers, but it doesn't put the X there when it reads the rows which are the same names -> it is a distance matrix). I am having an issue ordering my data so that one file with column names matches another file with the same row names (though in a different order) because if I read in a file that has the numeric names down the rows, it doesn't put the "X" in front of the name, but if I read in a file that has the numeric names across the columns, it puts an "X" before each name. Thus, I can't tell it to order/subset according to matching names because none of them match (because of that stupid X!!) I'm getting very frustrated because I can't do any more analysis on my data until I get this problem fixed. Please Help!!!

Here is a very small demonstration of my issue:

>data <- read.csv("filename.csv", row.names = 1)
>data
1 2 3
1 # # #

2 # # #

3 # # #

>names(data)
"X1" "X2" "X3"
>rownames(data)
"1" "2" "3"

How can I get this to stop?!?!?!
 

trinker

ggplot2orBust
#2
You shouldn't be doing this but you can if you as check.names=FALSE to the call as in:

Code:
read.table(text="    1      2          3   4    5
1 Qn1 Quebec nonchilled  95 16.0
2 Qn1 Quebec nonchilled 175 30.4
3 Qn1 Quebec nonchilled 250 34.8
4 Qn1 Quebec nonchilled 350 37.2
5 Qn1 Quebec nonchilled 500 35.3
6 Qn1 Quebec nonchilled 675 39.2", header=TRUE) [COLOR="red"]#what you got[/COLOR]


read.table(text="    1      2          3   4    5
1 Qn1 Quebec nonchilled  95 16.0
2 Qn1 Quebec nonchilled 175 30.4
3 Qn1 Quebec nonchilled 250 34.8
4 Qn1 Quebec nonchilled 350 37.2
5 Qn1 Quebec nonchilled 500 35.3
6 Qn1 Quebec nonchilled 675 39.2", header=TRUE, check.names=FALSE) [COLOR="red"]#what you want[/COLOR]
 

bryangoodrich

Probably A Mammal
#3
Frankly, I'd say if you're dealing with a distance matrix, then you don't need a data frame. A data frame is intended to be a multi-structured table. It is actually stored and handled differently in R (it's really just a list with elements that are single equal-length vectors). As such, a list element should not begin with a number. There's good technical reasons for this (hashable keys shouldn't be numeric, otherwise you might as well use array indexing). R handles this by default when reading in data frames.

What's the alternative? Read your matrix in as a matrix using scan or something. It'll not only be read in faster, you'll have better handling of your matrix in R as a matrix. A matrix is nothing but a vector with dimension attributes, but it is still just a vector. Vectors can have whatever names you want. Use rownames and colnames to manage matrix names (or dimnames if you're dealing with a higher dimensional matrix)
 
#4
Everytime I try to import CSV file as data.frame into R, there appears X in front of all column names. Attached file has screenshots of original csv & imported data.frame. I have used <- data.frame function. The goal is to process the csv / xls files using ordination methods using vegan package & other packages.
 

Attachments