मेरे पास निम्नलिखित वाक्य हैं जिन्हें मैं एक साथ जोड़ना चाहूंगा, लेकिन मैं चाहता हूं कि दूसरा वाक्य एक नए पैराग्राफ के रूप में शुरू हो:

Sentence 1: Premise: R is very useful for automating tasks at the office.
Sentence 2: Conclusion: Therefore, we should learn R.

मैं चाहता हूं कि दो वाक्य निम्नलिखित की तरह दिखें:

Premise: R is very useful for automating tasks at the office.

Conclusion: Therefore, we should learn R.

यहां मैंने अभी तक कोशिश की है:

sen.1 <- "Premise: R is very useful for automating tasks at the office."
sen.2 <- "Conclusion: Therefore, we should learn R."
paragrah <- cat(sen.1, sen.2)

paragraph
Premise: R is very useful for automating tasks at the office. Conclusion: Therefore, we should learn R.

अग्रिम में धन्यवाद!

0
Jim O. 20 अगस्त 2017, 00:24

3 जवाब

सबसे बढ़िया उत्तर

आपको बस दो न्यूलाइन कैरेक्टर डालने होंगे (\n):

sen.1 <- "Premise: R is very useful for automating tasks at the office."
sen.2 <- "Conclusion: Therefore, we should learn R."

# for printing directly, use `cat`
cat(sen.1, sen.2, sep = "\n\n")
#> Premise: R is very useful for automating tasks at the office.
#> 
#> Conclusion: Therefore, we should learn R.

# for saving as a variable for future printing, use `paste`
paragraph <- paste(sen.1, sen.2, sep = "\n\n")

# the print method of character vectors doesn't respect newlines...
paragraph
#> [1] "Premise: R is very useful for automating tasks at the office.\n\nConclusion: Therefore, we should learn R."

# ...so use `cat`
cat(paragraph)
#> Premise: R is very useful for automating tasks at the office.
#> 
#> Conclusion: Therefore, we should learn R.
4
alistaire 20 अगस्त 2017, 00:43

\n cat में लाइनब्रेक के लिए, लेकिन ध्यान दें कि यह कोई मूल्य नहीं देता है - बस कंसोल पर प्रिंट करता है, जाहिर तौर पर आप इसके आसपास काम कर सकते हैं capture.output...

paragrah  <- capture.output(cat(sen.1, "\n\n", sen.2))
paragrah

[1] "Premise: R is very useful for automating tasks at the office. "
[2] ""                                                              
[3] " Conclusion: Therefore, we should learn R." 

# Or simply
cat(sen.1, "\n\n", sen.2)
Premise: R is very useful for automating tasks at the office. 

 Conclusion: Therefore, we should learn R.
1
sindri_baldur 20 अगस्त 2017, 00:35

हम writeLines फ़ंक्शन का उपयोग कर सकते हैं, जो अलग-अलग स्ट्रिंग्स को अलग-अलग लाइनों में प्रिंट करेगा।

sen.1 <- "Premise: R is very useful for automating tasks at the office."
sen.2 <- "Conclusion: Therefore, we should learn R."

writeLines(c(sen.1, " ", sen.2))
Premise: R is very useful for automating tasks at the office.

Conclusion: Therefore, we should learn R.
1
www 20 अगस्त 2017, 00:43