rread.tableread.csvheader-row

Why does R think my imported vector of characters are numbers?


This is probably a basic question, but why does R think my vector, which has a bunch of words in it, are numbers when I try to use these vectors as column names?

I imported a data set and it turns out the first row of data are the column headers that I want. The column headers that came with the data set are wrong ones. So I want to replace the column names. I figured this should be easy.

So what I did was I extracted the first row of data into a new object:

names <- data[1,]

Then I deleted the first row of data:

data <- data[-1,]

Then I tried to rename the column headers with the "names" object:

colnames(data) <- names

However, when I do this, instead of changing my column names to the words within the names object, it turns it into a bunch of numbers. I have no idea where these numbers come from.

Thanks


Solution

  • You need to actually show us the data, and the read.csv()/read.table() command you used to import.

    If R thinks your numeric column is string, it sounds like that's because it wrongly includes the column name, i.e. you omitted header=TRUE in your read.csv()/read.table() import.

    But show us your actual data and commands used.