您好我将某些矩阵转换为data.frame并且在处理因子变量时会损坏:
> class(combn(as.factor(1:50), 2))
[1] "matrix"
# works
as.data.frame( t(combn(as.factor(1:50), 2)) )
# not work when shortened:
> as.data.frame( t(combn(as.factor(1:50)[1:2], 2)) )
t(combn(as.factor(1:50)[1:2], 2)).1 t(combn(as.factor(1:50)[1:2], 2)).2
1 1 2
2 <NA> <NA>
Warning message:
In format.data.frame(x, digits = digits, na.encode = FALSE) :
corrupt data frame: columns will be truncated or padded with NAs
# convert to numeric and works
> as.data.frame( t(combn(as.numeric(as.factor(1:50)[1:2]), 2)) )
V1 V2
1 1 2
有人可以告诉我为什么以及如何解决它(转换为数字修复它)?感谢...