我已经通过以下内容创建了一个向量,并希望为307 obs重复每列的值,以便我可以将它绑定到我拥有的数据帧:
weightvalues <- c(0.3,0.7,
0.3,0.4,0.2,0.1,
0.85,0.15,
0.25,0.25,0.2,0.2,0.1,
0.4,0.6,
0.4,0.6)
names(weightvalues) <- c("IC.TurnoverWeight","Branch.TurnoverWeight",
"Total.CallsWeight","Substantiated.CallsWeight","Unsubstantiated.CallsWeight","Branch.HeadcountWeight",
"PC.Cancel.RateWeight","TC.Cancel.RateWeight",
"VOE.2017.SERVWeight","VOE.2017.Acct.EmpWeight","VOE.2017.CustWeight","VOE.2017.EthicsWeight","VOE.2017.SafetyWeight",
"June.VOE.Participation.PercentWeight","July.VOE.Participation.PercentWeight",
"NPS.Score.TCWeight","NPS.Score.PCWeight")
weightvalues
FinalLaborUnrestDatLVs <- cbind(FinalLaborUnrestDatLVs,weightvalues)
显然,自从我的数据框&#34; FinalLaborUnrestDatLVs&#34;有307个观察结果它不会与我只有一个的载体结合。这里有一个简单的解决方案吗?
编辑:我想我可以使用代表,我只是在努力搞清楚这个功能。
答案 0 :(得分:0)
您可以转置向量以使其成为一行的矩阵,并且每列使用apply
到rep
307次:
FinalLaborUnrestDatLVs = cbind(FinalLaborUnrestDatLVs, apply(t(weightvalues), 2, rep, 307))