简体   繁体   English

R和rbind的串联,不格式化输出

[英]Concatenation in R with rbind without formatting output

Is there a way to concatenate "without" formating numbers ? 有没有一种方法可以连接“无”格式数字?

> 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 format numbers so the output is now... : 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

Can I get this kind of concatenation so R doesn't do additional formatting ? 我可以得到这种连接,以便R不执行其他格式化吗?

The columns in a data.frame are vectors. data.frame中的列是向量。 The elements in a vector are (must be) of the same type, for example numeric() or integer() . 向量中的元素必须是(必须是)相同的类型,例如numeric()integer() It seems you are trying to bind a data.frame of integer() s with a data.frame of numeric() s. 似乎您正在尝试将integer()的data.frame与numeric()的data.frame绑定。 R has no choice but coerce (convert) your integer() s into numeric() s, the reason why you now see ".000000". R别无选择,只能将integer()强制(转换)为numeric() ,这就是为什么现在看到“ .000000”的原因。

I don't think there is much you can do unless you are ok changing the way you store your results. 我认为您无法做很多事情,除非您可以更改存储结果的方式。 You could for example work with transposed versions of your data.frames, then use cbind() instead of rbind() . 例如,您可以使用cbind()转置版本,然后使用cbind()而不是rbind() This way, each column (your previous rows) can keep its own data type: 这样,每一列(您的前几行)可以保留自己的数据类型:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM