2013-10-26 31 views

回答

3

你可以只使用setNames

setNames(times, height) 
# 160 165 170 175 180 185 
# 2 4 5 6 3 1 

如果你想確保其classtable,敷在as.table

as.table(setNames(times, height)) 
# 160 165 170 175 180 185 
# 2 4 5 6 3 1 

使用後一種方法將讓你做出使用一些可用於table的方法。例如,想到的是data.frame方法。比較:

data.frame(setNames(times, height)) 
#  setNames.times..height. 
# 160      2 
# 165      4 
# 170      5 
# 175      6 
# 180      3 
# 185      1 

data.frame(as.table(setNames(times, height))) 
# Var1 Freq 
# 1 160 2 
# 2 165 4 
# 3 170 5 
# 4 175 6 
# 5 180 3 
# 6 185 1 
1

一種方式將有可能是這樣的:

table(rep(height, times)) 

160 165 170 175 180 185 
2 4 5 6 3 1 

其中高度的每一個元素將通過時間對同一指數的元素重複。

相關問題