查看数据帧的内容时是否可以截断输出?
我有一个数据框,其中有一些很长的“评论”列。当我显示它们时,它们被分成不同的块,使得跨行阅读变得困难。是否可以更改 R 中的设置或修改对 data.frame 的调用以截断特定长度的字符串?
示例:一个 3 列数据框
data.frame(cbind(rep(1,5),rep(c("very very long obnoxious character string here" ,"dog","cat","dog",5)),rep(c("very very long obnoxious character string here" ,"dog","cat","dog",5))))
在我的屏幕上看到的结果数据框:
X1 X2
1 1 very very long obnoxious character string here
2 1 dog
3 1 cat
4 1 dog
5 1 5
X3
1 very very long obnoxious character string here
2 dog
3 cat
4 dog
5 5
I have a data frame with some very long "comments" columns. When I have them displayed they are broken into different blocks, making it hard to read across rows. Is it possible to change a setting in R or modify the call to data.frame to truncate strings at a certain length?
Example: a 3-column dataframe
data.frame(cbind(rep(1,5),rep(c("very very long obnoxious character string here" ,"dog","cat","dog",5)),rep(c("very very long obnoxious character string here" ,"dog","cat","dog",5))))
Resulting dataframe as seen on my screen:
X1 X2
1 1 very very long obnoxious character string here
2 1 dog
3 1 cat
4 1 dog
5 1 5
X3
1 very very long obnoxious character string here
2 dog
3 cat
4 dog
5 5
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我推荐一种像这样的显式方式:
用法:
虽然可以更改默认行为,但我不推荐:
用法:
I recommend a kind of the explicit way like this:
usage:
Although it is possible to change the default behavior, I don't recommend:
usage: