的粘贴命令中有什么用

的粘贴命令中有什么用

本文介绍了'sep' 在 R 的粘贴命令中有什么用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 R 中使用 paste 命令,当我发现

I was working with the paste command in R, when I found that

a <- c("something", "to", "paste")
paste(a, sep="_")

产生输出

# [1] "something" "to" "paste"

这与我 print "a"

# [1] "something" "to" "paste"

那么 sep 对 R 中的 paste 命令有什么影响?

So what effect does the sep have on the paste command in R?

推荐答案

sep 在您有两个以上长度大于 1 的向量时更普遍适用.如果您希望获得 "something_to_paste",那么您将寻找 collapse 参数.

sep is more generally applicable when you have more than two vectors of length greater than 1. If you were looking to get "something_to_paste", then you would be looking for the collapse argument.

尝试以下操作以了解 sep 参数的作用:

Try the following to get a sense of what the sep argument does:

paste(a, 1:3, sep = "_")
# [1] "something_1" "to_2"        "paste_3"

并将其与 collapse 进行比较:

and compare it to collapse:

paste(a, collapse = "_")
# [1] "something_to_paste"

这篇关于'sep' 在 R 的粘贴命令中有什么用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 08:11