paste(x,collapse=“\n”) doesn't work? (R code)

你说的曾经没有我的故事 提交于 2019-12-12 02:04:31

问题


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

and I use paste(data_frame_name$b,collapse= "\n"), but I get

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

What can be the problem? Thanks.


回答1:


I think you're looking for cat:

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

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

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


来源:https://stackoverflow.com/questions/24725725/pastex-collapse-n-doesnt-work-r-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!