Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print, cat, paste in R separated by newline character

I want to do the print the elements of a vector line by line in R like below

1

2

3

However, when I do paste(c(1,2,3), "\n") or paste(c(1,2,3),sep = "\n"), the new line never gets printed out. The same thing goes for cat as well. I always get the following:

"1" "2" "3"

I would like to know to get around this problem.

like image 310
mynameisJEFF Avatar asked Jun 03 '14 08:06

mynameisJEFF


People also ask

How do you make text go to next line in R?

The most commonly used are "\t" for TAB, "\n" for new-line, and "\\" for a (single) backslash character.

How do you insert a line break in paste0 R?

paste0() converts its arguments to characters and combines them into a single string without separating the arguments. We can use the <br/> tag to create a line break to have each element appear on a separate line.

What is the cat function in R?

cat() function in R Language is used to print out to the screen or to a file.


1 Answers

The followings work in RStudio:

cat(1,2,3,sep="\n")

and

cat(1:3,sep="\n")

Both outputs are

1
2
3
like image 151
Anastasiya-Romanova 秀 Avatar answered Sep 21 '22 14:09

Anastasiya-Romanova 秀