我有一个要为其设置名称的数据框。我尝试使用rbind
函数。
我创建了一个名称向量,其名称与数据框列的编号相同。向量长度32。
names <- c("Pan troglodytes schweinfurthii A910","Pan troglodytes troglodytes A957",
"Pan troglodytes troglodytes A958", "Pan troglodytes troglodytes A960",
"Pan troglodytes verus A965", "Pan paniscus A914", "Pan paniscus A915",
"Pan paniscus A917", "Pan paniscus A919", "Pan paniscus A920 ",
"Pan paniscus A925", "Gorilla beringei graueri A929",
"Gorilla gorilla gorilla A931", "Gorilla gorilla gorilla A932",
"Gorilla gorilla gorilla A937", "Gorilla gorilla gorilla A962",
"Gorilla beringei graueri A967", "Pongo pygmaeus A943",
"Pongo pygmaeus A944", "Pongo abelii A947",
"Pongo abelii A949", "Pongo abelii A953", "Pongo abelii A955",
"Homo sapiens SD647", "Homo sapiens SD428", "Homo sapiens SD455",
"Homo sapiens SD583", "Homo sapiens SD643", "Homo sapiens SD961",
"Homo sapiens SD860","Homo sapiens SD249","Homo sapiens SD1067")
数据框看起来像是32列:
v218 v227 v254
A914.AVG_Beta A915.AVG_Beta A917.AVG_Beta
0.6289983 0.4749584 0.5873566 0.5803553
0.9145997 0.8802801 0.8940547 0.9315571
0.8656011 0.8590986 0.853209 0.9070981
当我跑步时:
tomas_data_450K_b_values <- rbind(names, process_tomas)
我得到警告:
有32条警告(请使用warnings()查看)
那结果:
v218 v227 v254
NA NA NA
A914.AVG_Beta A915.AVG_Beta A917.AVG_Beta
0.6289983 0.4749584 0.5873566 0.5803553
0.9145997 0.8802801 0.8940547 0.9315571
0.8656011 0.8590986 0.853209 0.9070981
如何将矢量名称设置为数据框名称,并用新名称保存数据框?
答案 0 :(得分:0)
您不能使用rbind
向列添加名称,因为那是为了合并数据行。您可以使用函数colnames()
colnames(my_data_frame) <- c("colname_1", "colname_2", "colname_3")