我很驚訝地看到R在連接向量時會將因素強制爲一個數字。即使級別相同,也會發生這種情況。例如:如何連接因子,而不將它們轉換爲整數級別?
> facs <- as.factor(c("i", "want", "to", "be", "a", "factor", "not", "an", "integer"))
> facs
[1] i want to be a factor not an integer
Levels: a an be factor i integer not to want
> c(facs[1 : 3], facs[4 : 5])
[1] 5 9 8 3 1
什麼是R(在我的情況下,這些向量可能會相當大)的地道方式?謝謝。
十分感謝!我剛纔發現,如果你事先不知道fac是一個因素類型,那麼unlist(list(facs [1:3],facs [4:5]))也可以工作。 – Keith 2010-08-09 20:18:08
以這種方式手動設置等級不適用於我的特殊問題。 (我有0級的水平,我可以減去1然後重新構造這個因子,但是,這是脆弱的,在scrutabality spectrum的較低端,即使是R.)相反(hooray?)我用'unlist列表(...))'。 – 2013-04-01 04:50:18