paste(x,collapse="\n") 不起作用?(R 代码) [英] paste(x,collapse="\n") doesn't work? (R code)

查看:110
本文介绍了paste(x,collapse="\n") 不起作用?(R 代码)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望有人能帮助我理解这种行分离的基本异常:

Hope someone can help me understand this basic anomaly of line separation:

a<-c("a","b","c") 
a
# [1] "a" "b" "c"
paste(a,collapse="\n")
# [1] "a\nb\nc"

基本上,我有一个数据框,如:

basically, I have a data frame like:

       a  b
1      6  228
2     10  148
3     20  124
4     34  165
5    100  165
6    200  165
7    310  165

我使用paste(data_frame_name$b,collapse="\n"),但我得到

[1] "228\n148\n124\n165\n165\n165\n165"

可能是什么问题?谢谢.

What can be the problem? Thanks.

推荐答案

我认为您正在寻找 cat:

cat(paste(a,collapse="\n"))
a
b
c

print 被调用以在您键入其名称时打印对象:

print is called to print an object when you type its name:

print(paste(a,collapse="\n"))
[1] "a\nb\nc"

这篇关于paste(x,collapse="\n") 不起作用?(R 代码)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆