How to write strings with new lines in R?

While writing the string vectors, we get them in a single line but we might want to represent strings in different lines especially in cases where each of the value of the string vector has a different meaning. This is helpful to the programmer as well as to any other reader. We can change the single line to multiple new lines using writeLines function in R.

Example

Reading with single line −

> String1 String1
[1] "Covid-19" "2020" "Lockdown" "Quarantine" "Life Changing"

Reading the same vector with new lines −

> String1 String2 writeLines(String2)
Tutorialspoint
SIMPLY EASY LEARNING
You are browsing the best resource for Online Education
Library
Videos
Ebooks
GATE Exams
Coding Ground
Current Affairs
UPSC Notes
Whiteboard
Net Meeting
Tutorix
> String3 writeLines(String3)
Office
IT
Academic
Development
Business
Design
Others
> String4 writeLines(String4)
Machine Learning
Computer Science
Web Development
Mobile App Development
Database Management
Microsoft Technologies
Big Data and Analytics
Updated on: 2020-08-11T14:35:54+05:30

419 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements