program story

R-print ()로 명시적인 줄 바꿈 문자를 추가해야합니까?

inputbox 2020. 12. 29. 07:02
반응형

R-print ()로 명시적인 줄 바꿈 문자를 추가해야합니까?


R에서 줄 바꾸기 문자를 어떻게 사용합니까?

myStringVariable <- "Very Nice ! I like";

myStringVariabel <- paste(myStringVariable, "\n", sep="");

위의 코드 는 작동하지 않습니다.

추신 : "R 줄 바꿈 문자"라는 쿼리가 Google을 혼란스럽게하는 것처럼 보이기 때문에 이런 종류의 검색을 할 때 중요한 문제가 있습니다. R이 다른 이름을 가졌 으면 좋겠어요.


R의 본질은 단순히 인쇄 할 때 문자형 벡터에 줄 바꿈이 전혀 없다는 것을 의미합니다.

> print("hello\nworld\n")
[1] "hello\nworld\n"

즉, 줄 바꿈 문자열에 있으며 새 줄로 인쇄되지 않습니다. 그러나 인쇄하려는 경우 cat 과 같은 다른 기능을 사용할 수 있습니다 .

> cat("hello\nworld\n")
hello
world

NewLine Char의 예 :

for (i in 1:5)
  {
   for (j in 1:i)
    {
     cat(j)
    }
    cat("\n")
  }

결과:

    1
    12
    123
    1234
    12345

당신은 또한 사용할 수 있습니다 writeLines.

> writeLines("hello\nworld")
hello
world

그리고 또한:

> writeLines(c("hello","world"))
hello
world

참조 URL : https://stackoverflow.com/questions/9317830/r-do-i-need-to-add-explicit-new-line-character-with-print

반응형