R でベクトルのすべての要素を 1 つの文字列に印刷するにはどうすればよいでしょうか? 質問する

R でベクトルのすべての要素を 1 つの文字列に印刷するにはどうすればよいでしょうか? 質問する

時々、ベクトル内のすべての要素を 1 つの文字列に印刷したいのですが、それでも要素は個別に印刷されます。

notes <- c("do","re","mi")
print(paste("The first three notes are: ", notes,sep="\t"))

つまり、次のようになります。

[1] "The first three notes are: \tdo" "The first three notes are: \tre"
[3] "The first three notes are: \tmi"

私が本当に望んでいるのは:

The first three notes are:      do      re      mi

ベストアンサー1

最も簡単な方法は組み合わせる1 つの関数を使用してメッセージとデータを生成しますc

paste(c("The first three notes are: ", notes), collapse=" ")
### [1] "The first three notes are:  do re mi"

おすすめ記事