如何将向量转换为R数据帧中的变量名?

如何将向量转换为R数据帧中的变量名?,r,dataframe,R,Dataframe,我想做的很简单。我有一个名向量,它将成为数据帧中的变量名。最终结果是(最初)没有数据的数据帧,但根据称为“标签”的向量,有210个命名变量。有什么办法吗 vector0 <- c("a", "b", "c", "d", "e", "f", "g") vector1 <- rep(1:3, times=1, each=70) vector2 <- rep(1:5, times=1, each=14) vector3 <- rep(1:2, times=1, each=7)

我想做的很简单。我有一个名向量,它将成为数据帧中的变量名。最终结果是(最初)没有数据的数据帧,但根据称为“标签”的向量,有210个命名变量。有什么办法吗

vector0 <- c("a", "b", "c", "d", "e", "f", "g")
vector1 <- rep(1:3, times=1, each=70)
vector2 <- rep(1:5, times=1, each=14)
vector3 <- rep(1:2, times=1, each=7)
label <- paste(vector0, vector1, vector2, vector3, sep="")
vector0你说“没有数据”,所以我想你想要的是一个没有任何数据的数据帧,甚至不是NA的:

df <- as.data.frame(replicate(210, numeric()))

df
df我不清楚最终结果是什么。
names(df) <- label # `label` from OP
df <- setNames(as.data.frame(replicate(210, numeric())), label)