Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

r

paste

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.

like image 814
Alexander Mints Avatar asked Jul 30 '26 08:07

Alexander Mints


1 Answers

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"
like image 172
Matthew Lundberg Avatar answered Aug 02 '26 02:08

Matthew Lundberg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!