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.
The most commonly used are "\t" for TAB, "\n" for new-line, and "\\" for a (single) backslash character.
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.
cat() function in R Language is used to print out to the screen or to a file.
The followings work in RStudio:
cat(1,2,3,sep="\n")
and
cat(1:3,sep="\n")
Both outputs are
1
2
3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With