- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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<-c("Covid-19","2020","Lockdown","Quarantine","Life Changing") > String1 [1] "Covid-19" "2020" "Lockdown" "Quarantine" "Life Changing"
Reading the same vector with new lines −
> String1<-writeLines(c("Covid-19","2020","Lockdown","Quarantine","Life Changing")) Covid-19 2020 Lockdown Quarantine Life Changing > String2<-c("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") > 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<-c("Office","IT","Academic","Development","Business","Design","Others") > writeLines(String3) Office IT Academic Development Business Design Others > String4<-c("Machine Learning","Computer Science","Web Development","Mobile App Development","Database Management","Microsoft Technologies", + "Big Data and Analytics") > writeLines(String4) Machine Learning Computer Science Web Development Mobile App Development Database Management Microsoft Technologies Big Data and Analytics
- Related Articles
- How to write long strings in Multi-lines C/C++?
- How to create a circle with vertical lines in R?
- How to write the plot title in multiple lines using plot function in R?
- How to concatenate strings in R?
- How to create multiple lines chart with unique line types in R?
- How to separate strings in R that are joined with special characters?
- How to join points in a point chart with lines using ggplot2 in R?
- How to create boxplot with horizontal lines on the minimum and maximum in R?
- How to create boxplot in base R with higher width of the box lines?
- How to create horizontal lines with two different colors after a threshold in R?
- How to delete lines after creating a line chart with points in base R?
- How to write multiple line strings using Bash with variables on Linux?
- Why can’t raw strings (r-strings) end with a backslash in Python?
- How to replace numbers with ordinal strings for a survey in an R vector?
- How to remove unique characters within strings in R?

Advertisements