如何以零作为中点创建一个从min到最大的数字序列?
如果我有以下变量。
set.seed(20)
variable <- sample(-74:124.2, size = 38)
如何使用变量
的最小值和零作为中点(第3个值)创建5个数字的序列?
seq()
采用启动和结束值,但是有没有办法通过指定中间值来做到这一点?
seq(min(variable), max(variable), length.out = 5)
If I had the following variable.
set.seed(20)
variable <- sample(-74:124.2, size = 38)
How can I create a sequence of 5 numbers using the min and max values of variable
and zero as the midpoint (3rd value)?
seq()
takes the start and end values, but is there a way to do this by specifying a middle value?
seq(min(variable), max(variable), length.out = 5)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以用指定的值替换生成序列的中间:
如果
length(x)
是奇数,则可以使用。You can replace the
median
of the generated sequence with a specified value:This would work if the
length(x)
is odd.您可以组合两个
seq
。这仅在
min(variable)&lt; = 0
和max(variable)&gt; = 0
时,才能按预期工作。You can combine two
seq
.This will only work as expected when
min(variable) <= 0
andmax(variable) >= 0
.