Seal, cat, insert in R, separated by a newline

I want to print the elements of a vector line by line in R as shown below

1

2

3

However, when I do paste(c(1,2,3), "\n")or paste(c(1,2,3),sep = "\n"), a new line will never be printed. The same applies to cat. I always get the following:

"1" "2" "3"

I would like to know to get around this problem.

+4
source share
3 answers

Try:

cat(paste(1:3), sep="\n")
1
2
3
+6
source

writeLinesdesigned for this purpose. You need to specify a character vector:

writeLines(as.character(1:3))
1
2
3
+3
source

RStudio :

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

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

1
2
3
+1

Source: https://habr.com/ru/post/1543029/


All Articles