4

So I have a data frame (called SNPlist) which is of dimensions 1 by 500000 (rows by columns). I want SNP list to be the column names for my dataframe of data (called Data) which is of dimension 100 by 500000. I already tried colnames(Data) <- SNPlist but it does not seem to be working. Can anyone help with this issue?

starball
  • 20,030
  • 7
  • 43
  • 238

3 Answers3

5

If SNPlist is a data.frame, then you need to point to the first row of it:

colnames(Data) <- SNPlist[1, ]

If it was a vector, what you'd tried would have worked

alexwhan
  • 15,636
  • 5
  • 52
  • 66
3

It's been a while since the question was asked, but I noticed nobody suggested what works for me: colnames(Data) <- colnames(SNPlist)

Amos

Amos
  • 43
  • 5
0

I was having a lot of trouble with this because the usual method (provided above by alexwhan) wasn't getting it done. I eventually got around it by first ripping out a headers vector from the old data frame and using the names function to slap it on the new one.

names(new_DF) <- as.character(apply(old_DF["wanted_header_row", ], 1, paste))

Perhaps it's a bit much, but it was the only thing that worked for me.

J.M.S.
  • 95
  • 7