如何在 R 中编写具有新行的字符串?
在编写字符串向量时,我们会在单行中获取它们,但我们可能希望在不同的行中表示字符串,尤其是在字符串向量的各个值具有不同含义的情况下。这对编程人员和任何其他读者都有帮助。我们可以使用 R 中的 `writeLines` 函数将单行更改为多个新行。
示例
单行读取 −
> String1<-c("Covid-19","2020","Lockdown","Quarantine","Life Changing") > String1 [1] "Covid-19" "2020" "Lockdown" "Quarantine" "Life Changing"
在新行中读取相同向量 −
> 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
广告