0
我想重複一個因子,如下圖所示:我不確定這是否可以使用rep()
函數完成?重複因子元素
輸入:
c("100G","105G","302G")
出來:
c("100G","100G","100G","100G","100G","105G","105G","105G","105G","105G","302G","302G","302G","302G","302G")
我想重複一個因子,如下圖所示:我不確定這是否可以使用rep()
函數完成?重複因子元素
輸入:
c("100G","105G","302G")
出來:
c("100G","100G","100G","100G","100G","105G","105G","105G","105G","105G","302G","302G","302G","302G","302G")
這是可以做到的:
inputVec <- c("100G","105G","302G")
outputVec <- rep(inputVec, each = 5)
outputVec
是的,這是可以做到...
這應該訣竅:
rep(c("100G","105G","302G"), each=10)
'rep'可以接受多個選項,即'each'或'times'如果我們要使用'times',則長度應該與初始向量相同。 'rep(v1,times = c(5,6,7))' – akrun
使它成爲答案 – petermeissner