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?
所以我有一个数据框(称为SNPlist),其尺寸为1乘500000(逐列)。我希望SNP列表是我的数据数据帧(称为数据)的列名,其大小为100乘500000.我已经尝试过colnames(Data)< - SNPlist但它似乎没有工作。有人可以帮忙解决这个问题吗?
Thanks
谢谢
2 个解决方案
#1
2
If SNPlist
is a data.frame
, then you need to point to the first row of it:
如果SNPlist是data.frame,那么您需要指向它的第一行:
colnames(Data) <- SNPlist[1, ]
If it was a vector, what you'd tried would have worked
如果它是一个矢量,你尝试过的东西会起作用
#2
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.
我在这方面遇到了很多麻烦,因为通常的方法(由alexwhan提供)并没有完成它。我最终通过从旧数据框中删除标题向量并使用名称函数将其打到新数据框上来解决它。
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.
也许它有点多,但它是唯一对我有用的东西。
#1
2
If SNPlist
is a data.frame
, then you need to point to the first row of it:
如果SNPlist是data.frame,那么您需要指向它的第一行:
colnames(Data) <- SNPlist[1, ]
If it was a vector, what you'd tried would have worked
如果它是一个矢量,你尝试过的东西会起作用
#2
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.
我在这方面遇到了很多麻烦,因为通常的方法(由alexwhan提供)并没有完成它。我最终通过从旧数据框中删除标题向量并使用名称函数将其打到新数据框上来解决它。
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.
也许它有点多,但它是唯一对我有用的东西。