Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set a dataframe as column names for another data frame

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?


2 Answers

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

like image 174
alexwhan Avatar answered Oct 16 '25 18:10

alexwhan


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

Amos

like image 24
Amos Avatar answered Oct 16 '25 18:10

Amos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!