R中的连接与rbind没有格式化输出

时间:2012-02-18 03:20:01

标签: r

有没有办法连接“不”形成数字?

> pos.ord
Gb19a Gb19b Gb24a Gb24b Gb28a Gb28b Gb11a Gb11b
378   386   246   248   360   372   162   261
380   386   246   248   360   372   187   261

> table.error.means
   Gb19a    Gb19b    Gb24a    Gb24b    Gb28a    Gb28b    Gb11a    Gb11b 
2.380952 2.380952 7.539683 7.539683 5.952381 5.158730 5.952381 5.158730

> rbind(pos.ord, table.error.means)

rbind格式编号,所以输出现在是......:

Gb19a      Gb19b      Gb24a      Gb24b     Gb28a      Gb28b
378.000000 386.000000 246.000000 248.000000 360.00000 372.000000
380.000000 386.000000 246.000000 248.000000 360.00000 372.000000
2.380952   7.539683   7.539683   5.952381   5.15873   5.952381

我可以获得这种连接,因此R不会进行其他格式化吗?

1 个答案:

答案 0 :(得分:3)

data.frame中的列是向量。向量中的元素(必须)具有相同的类型,例如numeric()integer()。您似乎正在尝试将integer() s的data.frame绑定到numeric() s的data.frame。 R别无选择,只能将integer()强制(转换)为numeric() s,这就是您现在看到“.000000”的原因。

除非您改变存储结果的方式,否则我认为您无法做很多事情。例如,您可以使用data.frames的转置版本,然后使用cbind()代替rbind()。这样,每列(您之前的行)都可以保留自己的数据类型:

pos.ord <- t(pos.ord)
table.error.means <- t(table.error.means)
cbind(pos.ord, table.error.means)